Skip to content

Commit ccf548e

Browse files
committed
enhance: added info to config editor
1 parent 95093e8 commit ccf548e

File tree

6 files changed

+73
-21
lines changed

6 files changed

+73
-21
lines changed

frontend/components.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ declare module '@vue/runtime-core' {
7676
NginxControlNginxControl: typeof import('./src/components/NginxControl/NginxControl.vue')['default']
7777
NodeSelectorNodeSelector: typeof import('./src/components/NodeSelector/NodeSelector.vue')['default']
7878
PageHeaderPageHeader: typeof import('./src/components/PageHeader/PageHeader.vue')['default']
79+
RightSettingsDeploy: typeof import('./src/components/RightSettings/Deploy.vue')['default']
80+
RightSettingsRightSettings: typeof import('./src/components/RightSettings/RightSettings.vue')['default']
81+
RightSettingsSiteDuplicate: typeof import('./src/components/RightSettings/SiteDuplicate.vue')['default']
7982
RouterLink: typeof import('vue-router')['RouterLink']
8083
RouterView: typeof import('vue-router')['RouterView']
8184
SetLanguageSetLanguage: typeof import('./src/components/SetLanguage/SetLanguage.vue')['default']

frontend/src/components/NodeSelector/NodeSelector.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const value = computed({
4646
<a-tag color="error" v-else>{{ $gettext('Offline') }}</a-tag>
4747
</a-col>
4848
</a-row>
49+
<a-empty v-if="hidden_local&&data.length===0"/>
4950
</a-checkbox-group>
5051
</template>
5152

frontend/src/views/config/ConfigEdit.vue

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import CodeEditor from '@/components/CodeEditor/CodeEditor.vue'
99
import ngx from '@/api/ngx'
1010
import InspectConfig from '@/views/config/InspectConfig.vue'
1111
import ChatGPT from '@/components/ChatGPT/ChatGPT.vue'
12+
import {formatDateTime} from '../../lib/helper'
1213
1314
const {$gettext, interpolate} = gettext
1415
const route = useRoute()
@@ -26,13 +27,16 @@ const name = computed(() => {
2627
const configText = ref('')
2728
const history_chatgpt_record = ref([])
2829
const file_path = ref('')
30+
const active_key = ref(['1', '2'])
31+
const modified_at = ref('')
2932
3033
function init() {
3134
if (name.value) {
3235
config.get(name.value).then(r => {
3336
configText.value = r.config
3437
history_chatgpt_record.value = r.chatgpt_messages
3538
file_path.value = r.file_path
39+
modified_at.value = r.modified_at
3640
}).catch(r => {
3741
message.error(r.message ?? $gettext('Server error'))
3842
})
@@ -90,15 +94,45 @@ function format_code() {
9094
</a-card>
9195
</a-col>
9296

93-
<a-col class="col-right" :xs="24" :sm="24" :md="6">
94-
<a-card>
95-
<chat-g-p-t :content="configText" :path="file_path"
96-
v-model:history_messages="history_chatgpt_record"/>
97+
<a-col :xs="24" :sm="24" :md="6">
98+
<a-card class="col-right">
99+
<a-collapse v-model:activeKey="active_key" ghost>
100+
<a-collapse-panel key="1" :header="$gettext('Basic')">
101+
<a-form layout="vertical">
102+
<a-form-item :label="$gettext('Path')">
103+
{{ file_path }}
104+
</a-form-item>
105+
<a-form-item :label="$gettext('Updated at')">
106+
{{ formatDateTime(modified_at) }}
107+
</a-form-item>
108+
</a-form>
109+
</a-collapse-panel>
110+
<a-collapse-panel key="2" header="ChatGPT">
111+
<chat-g-p-t :content="configText" :path="file_path"
112+
v-model:history_messages="history_chatgpt_record"/>
113+
</a-collapse-panel>
114+
</a-collapse>
97115
</a-card>
98116
</a-col>
99117
</a-row>
100118
</template>
101119

102120
<style lang="less" scoped>
121+
.col-right {
122+
position: sticky;
123+
top: 78px;
103124
125+
:deep(.ant-card-body) {
126+
max-height: 100vh;
127+
overflow-y: scroll;
128+
}
129+
}
130+
131+
:deep(.ant-collapse-ghost > .ant-collapse-item > .ant-collapse-content > .ant-collapse-content-box) {
132+
padding: 0;
133+
}
134+
135+
:deep(.ant-collapse > .ant-collapse-item > .ant-collapse-header) {
136+
padding: 0 0 10px 0;
137+
}
104138
</style>

frontend/src/views/domain/components/RightSettings.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const history_chatgpt_record = inject('history_chatgpt_record')
1919
const filename = inject('filename')
2020
const data: any = inject('data')
2121
22-
const active_key = ref('1')
22+
const active_key = ref(['1', '2', '3'])
2323
2424
function enable() {
2525
domain.enable(name.value).then(() => {

server/api/config.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/0xJacky/Nginx-UI/server/internal/nginx"
77
"github.com/0xJacky/Nginx-UI/server/query"
88
"github.com/gin-gonic/gin"
9+
"github.com/sashabaranov/go-openai"
910
"net/http"
1011
"os"
1112
)
@@ -78,6 +79,13 @@ func GetConfig(c *gin.Context) {
7879
name := c.Param("name")
7980
path := nginx.GetConfPath("/", name)
8081

82+
stat, err := os.Stat(path)
83+
84+
if err != nil {
85+
ErrHandler(c, err)
86+
return
87+
}
88+
8189
content, err := os.ReadFile(path)
8290

8391
if err != nil {
@@ -93,10 +101,15 @@ func GetConfig(c *gin.Context) {
93101
return
94102
}
95103

104+
if chatgpt.Content == nil {
105+
chatgpt.Content = make([]openai.ChatCompletionMessage, 0)
106+
}
107+
96108
c.JSON(http.StatusOK, gin.H{
97109
"config": string(content),
98110
"chatgpt_messages": chatgpt.Content,
99111
"file_path": path,
112+
"modified_at": stat.ModTime(),
100113
})
101114

102115
}

server/model/chatgpt_log.go

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,35 @@
11
package model
22

33
import (
4-
"database/sql/driver"
5-
"encoding/json"
6-
"fmt"
7-
"github.com/pkg/errors"
8-
"github.com/sashabaranov/go-openai"
4+
"database/sql/driver"
5+
"encoding/json"
6+
"fmt"
7+
"github.com/pkg/errors"
8+
"github.com/sashabaranov/go-openai"
99
)
1010

1111
type JSON []openai.ChatCompletionMessage
1212

1313
// Scan scan value into Jsonb, implements sql.Scanner interface
1414
func (j *JSON) Scan(value interface{}) error {
15-
bytes, ok := value.([]byte)
16-
if !ok {
17-
return errors.New(fmt.Sprint("Failed to unmarshal JSONB value:", value))
18-
}
15+
bytes, ok := value.([]byte)
16+
if !ok {
17+
return errors.New(fmt.Sprint("Failed to unmarshal JSONB value:", value))
18+
}
1919

20-
result := make([]openai.ChatCompletionMessage, 0)
21-
err := json.Unmarshal(bytes, &result)
22-
*j = result
23-
return err
20+
result := make([]openai.ChatCompletionMessage, 0)
21+
err := json.Unmarshal(bytes, &result)
22+
*j = result
23+
24+
return err
2425
}
2526

2627
// Value return json value, implement driver.Valuer interface
2728
func (j *JSON) Value() (driver.Value, error) {
28-
return json.Marshal(*j)
29+
return json.Marshal(*j)
2930
}
3031

3132
type ChatGPTLog struct {
32-
Name string `json:"name"`
33-
Content JSON `json:"content" gorm:"serializer:json"`
33+
Name string `json:"name"`
34+
Content JSON `json:"content" gorm:"serializer:json"`
3435
}

0 commit comments

Comments
 (0)