Skip to content

Commit

Permalink
technical debt
Browse files Browse the repository at this point in the history
  • Loading branch information
e154 committed Dec 19, 2023
1 parent acd2a85 commit 471f8a7
Show file tree
Hide file tree
Showing 10 changed files with 140 additions and 28 deletions.
1 change: 1 addition & 0 deletions cmd/server/container/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,6 @@ func MigrationList(adaptors *adaptors.Adaptors,
local_migrations.NewMigrationSpeedtest(adaptors),
local_migrations.NewMigrationBackup(adaptors),
local_migrations.NewMigrationGate(adaptors),
local_migrations.NewMigrationAddVar1(adaptors),
}
}
25 changes: 24 additions & 1 deletion static_source/admin/src/components/Infotip/src/Infotip.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const prefixCls = getPrefixCls('infotip')
defineProps({
title: propTypes.string.def(''),
type: propTypes.string.def(''),
schema: {
type: Array as PropType<Array<string | TipSchema>>,
required: true,
Expand All @@ -28,7 +29,7 @@ const keyClick = (key: string) => {
</script>

<template>
<div
<div v-if="type != 'warning'"
style="border-left: 5px solid var(--el-color-primary); border-radius: 4px;"
:class="[
prefixCls,
Expand All @@ -50,4 +51,26 @@ const keyClick = (key: string) => {
</p>
</div>
</div>
<div v-if="type == 'warning'"
style="border-left: 5px solid var(--el-color-warning); border-radius: 4px;"
:class="[
prefixCls,
'p-20px mb-20px border-solid border-[var(--el-color-warning)] bg-[var(--el-color-warning-light-9)]'
]"
>
<div v-if="title" :class="[`${prefixCls}__header`, 'flex items-center']">
<span :class="[`${prefixCls}__title`, 'text-14px font-bold']">{{ title }}</span>
</div>
<div :class="`${prefixCls}__content`">
<p v-for="(item, $index) in schema" :key="$index" class="text-12px mt-10px">
<Highlight
:keys="typeof item === 'string' ? [] : item.keys"
:color="highlightColor"
@click="keyClick"
>
{{ showIndex ? `${$index + 1}、` : '' }}{{ typeof item === 'string' ? item : item.label }}
</Highlight>
</p>
</div>
</div>
</template>
2 changes: 2 additions & 0 deletions static_source/admin/src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,8 @@ export default {
createBackupAt: 'Create Backup At (Cron)',
maximumNumberOfBackups: 'Maximum Number Of Backups',
info1: 'https://en.wikipedia.org/wiki/Cron',
info2: 'free gate https://gate.e154.ru:8443',
info3: 'don\'t change it if you don\'t know what it\'s for',
sendTheBackupInPartsMb: 'Send The Backup In Parts Mb',
sendbackuptoTelegramBot: 'Send Backup To Telegram Bot',
gate: 'Gate',
Expand Down
2 changes: 2 additions & 0 deletions static_source/admin/src/locales/ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,8 @@ export default {
createBackupAt: 'Когда создавать кипию (cron)',
maximumNumberOfBackups: 'Максимальное количество резервных копий',
info1: 'https://en.wikipedia.org/wiki/Cron',
info2: 'тестовый шлюз https://gate.e154.ru:8443',
info3: 'не меняй, если не знаешь для чего это',
sendTheBackupInPartsMb: 'Отправлять резервную копию по частям Mb',
sendbackuptoTelegramBot: 'Отправить резервную копию боту Telegram',
gate: 'Шлюз',
Expand Down
21 changes: 21 additions & 0 deletions static_source/admin/src/views/Settings/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,16 @@ getSettings()

<ElDivider content-position="left">{{$t('settings.gate')}}</ElDivider>

<Infotip
:show-index="false"
title="INFO"
:schema="[
{
label: t('settings.info2'),
},
]"
/>

<ElRow :gutter="24">
<ElCol :span="12" :xs="12">
<ElFormItem :label="$t('settings.gateClientServerHost')" prop="gateClientServerHost">
Expand Down Expand Up @@ -322,6 +332,17 @@ getSettings()

<ElDivider content-position="left">{{$t('settings.hmacKey')}}</ElDivider>

<Infotip
type="warning"
:show-index="false"
title="WARNING"
:schema="[
{
label: t('settings.info3'),
},
]"
/>

<ElRow :gutter="24">
<ElCol :span="12" :xs="12">
<ElFormItem :label="$t('settings.hmacKey')" prop="hmacKey">
Expand Down
5 changes: 3 additions & 2 deletions system/initial/initial.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,9 @@ func (n *Initial) checkForUpgrade() {

if errors.Is(err, apperr.ErrNotFound) {
v = m.Variable{
Name: name,
Value: fmt.Sprintf("%d", 1),
Name: name,
Value: fmt.Sprintf("%d", 1),
System: true,
}
err = n.adaptors.Variable.Add(context.Background(), v)
So(err, ShouldBeNil)
Expand Down
45 changes: 45 additions & 0 deletions system/initial/local_migrations/m_add_var1.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// This file is part of the Smart Home
// Program complex distribution https://github.com/e154/smart-home
// Copyright (C) 2023, Filippov Alex
//
// This library is free software: you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 3 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library. If not, see
// <https://www.gnu.org/licenses/>.

package local_migrations

import (
"context"

"github.com/e154/smart-home/adaptors"
)

type MigrationAddVar1 struct {
adaptors *adaptors.Adaptors
}

func NewMigrationAddVar1(adaptors *adaptors.Adaptors) *MigrationAddVar1 {
return &MigrationAddVar1{
adaptors: adaptors,
}
}

func (n *MigrationAddVar1) Up(ctx context.Context, adaptors *adaptors.Adaptors) error {
if adaptors != nil {
n.adaptors = adaptors
}

AddVariableIfNotExist(n.adaptors, ctx, "restartComponentIfScriptChanged", "false")
AddVariableIfNotExist(n.adaptors, ctx, "sendTheBackupInPartsMb", "0")
return nil
}
59 changes: 36 additions & 23 deletions system/initial/local_migrations/m_dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ package local_migrations

import (
"context"
"fmt"

"github.com/e154/smart-home/adaptors"
m "github.com/e154/smart-home/models"
. "github.com/e154/smart-home/system/initial/assertions"
)

type MigrationDashboard struct {
Expand All @@ -34,37 +37,47 @@ func NewMigrationDashboard(adaptors *adaptors.Adaptors) *MigrationDashboard {
}
}

func (n *MigrationDashboard) addDashboard(ctx context.Context, name, src string) error {

//req := &api.Dashboard{}
//_ = json.Unmarshal([]byte(src), req)
//
//board := dto.ImportDashboard(req)
//
//var err error
//if board.Id, err = n.adaptors.Dashboard.Import(ctx, board); err != nil {
// return err
//}
//
//err = n.adaptors.Variable.CreateOrUpdate(ctx, m.Variable{
// Name: name,
// Value: fmt.Sprintf("%d", board.Id),
// System: true,
//})
func (n *MigrationDashboard) addDashboard(ctx context.Context, name, _n, _d string) error {

return nil
if _, err := n.adaptors.Variable.GetByName(ctx, name); err == nil {
return nil
}

board := &m.Dashboard{
Name: _n,
Description: _d,
}

var err error
if board.Id, err = n.adaptors.Dashboard.Add(ctx, board); err != nil {
return err
}

err = n.adaptors.Variable.Update(ctx, m.Variable{
Name: name,
Value: fmt.Sprintf("%d", board.Id),
System: true,
})

return err
}

func (n *MigrationDashboard) Up(ctx context.Context, adaptors *adaptors.Adaptors) error {
if adaptors != nil {
n.adaptors = adaptors
}

//err := n.addDashboard(ctx, "devDashboard", devDashboardRaw)
//So(err, ShouldBeNil)
//
//err = n.addDashboard(ctx, "mainDashboard", mainDashboardRaw)
//So(err, ShouldBeNil)
err := n.addDashboard(ctx, "devDashboardLight", "develop (light theme)", "DEVELOP")
So(err, ShouldBeNil)

err = n.addDashboard(ctx, "devDashboardDark", "develop (dark theme)", "DEVELOP")
So(err, ShouldBeNil)

err = n.addDashboard(ctx, "mainDashboardLight", "main (light theme)", "MAIN")
So(err, ShouldBeNil)

err = n.addDashboard(ctx, "mainDashboardDark", "main (dark theme)", "MAIN")
So(err, ShouldBeNil)

return nil
}
2 changes: 1 addition & 1 deletion system/initial/local_migrations/m_scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (n *MigrationScheduler) Up(ctx context.Context, adaptors *adaptors.Adaptors
n.adaptors = adaptors
}

err := AddVariableIfNotExist(n.adaptors, ctx, "gate_client_id", "60")
err := AddVariableIfNotExist(n.adaptors, ctx, "clearMetricsDays", "60")
So(err, ShouldBeNil)
err = AddVariableIfNotExist(n.adaptors, ctx, "clearLogsDays", "60")
So(err, ShouldBeNil)
Expand Down
6 changes: 5 additions & 1 deletion system/initial/local_migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ func (t *Migrations) Up(ctx context.Context, adaptors *adaptors.Adaptors, ver st
return
}

for _, migration := range t.list[position+1 : len(t.list)] {
if position > 0 {
position++
}

for _, migration := range t.list[position:len(t.list)] {
if err = ctx.Err(); err != nil {
log.Error(err.Error())
return
Expand Down

0 comments on commit 471f8a7

Please sign in to comment.