Удаление ненужных сообщений, удаление дублирования кода update viewport final, исправление приведени типов, работа над viewport form, исправление динамических секций

This commit is contained in:
XeRo 2026-01-16 17:44:03 +05:00
parent 300afb5d26
commit ecc89e34c5
11 changed files with 168 additions and 142 deletions

View file

@ -13,6 +13,7 @@ func Start() {
}
}
// todo подсказка горячие клавиши
// Main структура описывающая объект настроек
type Main struct {
current tea.Model //Текущая модель для отображения
@ -94,38 +95,40 @@ func (m *Main) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
case types.NextSectionMsg:
//Получаем сообщение о переходе на следующую секцию настраиваемого приложения.
//Увеличиваем индекс текущей секции.
m.CurrentSectionIdx++
//Если новый индекс равен
if m.CurrentSectionIdx == len(m.CurrentApplication.Sections) {
//todo что делать когда секций больше нужного?
return m, tea.Quit
}
for sectionIdx := m.CurrentSectionIdx; sectionIdx < len(m.CurrentApplication.Sections); sectionIdx++ {
//todo переделать. Учесть динамические индексы.
//Ищем индекс следующей секции, если он остался 0, то следующие секции недоступны.
//Возвращаем модальное окно с выходом к списку приложений
nextSectionIndex := 0
for sectionIdx := m.CurrentSectionIdx + 1; sectionIdx < len(m.CurrentApplication.Sections); sectionIdx++ {
section := m.CurrentApplication.Sections[sectionIdx]
if CheckCondition(section.Condition, m.CurrentApplication) {
m.CurrentSectionIdx = sectionIdx
m.CurrentSection = &section
nextSectionIndex = sectionIdx
break
}
}
if m.CurrentSection == nil {
if nextSectionIndex == 0 {
return m, func() tea.Msg {
return types.ShowModalMsg{
Type: types.ModalError,
Title: "Ошибка конфигурации",
Message: "Это приложение не имеет доступных секций для настройки\n" +
"Возможно оно повреждено или не поддерживается",
ModalButtons: []types.ModalButton{{Text: "Выйти", Value: true}},
Type: types.ModalWarning,
Title: "Ошибка секций приложения",
Message: "Указанное приложение не имеет больше доступных секций для обработки",
ModalButtons: []types.ModalButton{{
Text: "Вернутся",
Value: true,
}},
OnResult: func(result any) tea.Cmd {
return tea.Quit
return func() tea.Msg {
return types.BackToListMsg{}
}
},
}
}
}
//todo переделать. Учесть динамические индексы.
if m.CurrentSectionIdx == len(m.CurrentApplication.Sections)-1 && m.CurrentSection.Type == types.SectionFinal {
//Если следующая секция доступна записываем секцию и её индекс.
//Выводим либо финальную форму, если секция последняя и её тип SectionFinal, либо следующую простую секцию.
m.CurrentSectionIdx = nextSectionIndex
m.CurrentSection = &m.CurrentApplication.Sections[nextSectionIndex]
if nextSectionIndex == len(m.CurrentApplication.Sections)-1 && m.CurrentSection.Type == types.SectionFinal {
m.current = NewFinalModel(m.CurrentApplication.Variables, m.Width, m.Height)
} else {
m.current = NewFormModel(m.CurrentApplication, m.CurrentSectionIdx, 0, m.Width, m.Height)
@ -152,7 +155,7 @@ func (m *Main) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
Title: "Ошибка",
Message: "Ошибка выбора приложения. Указанное приложение не имеет доступных секций." +
"Проверьте конфиг настраиваемого приложения на предмет выполнения условий секций",
ModalButtons: []types.ModalButton{{Text: "Вернуться к списку приложений", Value: true}},
ModalButtons: []types.ModalButton{{Text: "Вернуться", Value: true}},
OnResult: func(result any) tea.Cmd {
return func() tea.Msg {
return types.BackToListMsg{}
@ -204,11 +207,8 @@ func (m *Main) Sugar(sugar types.SugarMsg) {
m.DeactivateField(sugar.VariableName, sugar.FieldName)
}
//Если от переменной поля зависит секции или поля,
//то вызываем перерасчет значений compute полей и формируем новую форму с учетом прошлого фокуса на форме
//то формируем новую форму с учетом прошлого фокуса
if IsParent(sugar.VariableName, m.CurrentApplication.Sections) {
if sugar.Compute != "" {
Recompute(m.CurrentApplication)
}
m.current = NewFormModel(m.CurrentApplication, m.CurrentSectionIdx, sugar.Focus, m.Width, m.Height)
}
}