Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions agent/app/dto/request/website.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type WebsiteSearch struct {
OrderBy string `json:"orderBy" validate:"required,oneof=primary_domain type status createdAt expire_date created_at"`
Order string `json:"order" validate:"required,oneof=null ascending descending"`
WebsiteGroupID uint `json:"websiteGroupId"`
Type string `json:"type"`
}

type WebsiteCreate struct {
Expand Down
7 changes: 7 additions & 0 deletions agent/app/repo/website.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type IWebsiteRepo interface {
WithDomainLike(domain string) DBOption
WithRuntimeID(runtimeID uint) DBOption
WithParentID(websiteID uint) DBOption
WithType(websiteType string) DBOption

Page(page, size int, opts ...DBOption) (int64, []model.Website, error)
List(opts ...DBOption) ([]model.Website, error)
Expand Down Expand Up @@ -93,6 +94,12 @@ func (w *WebsiteRepo) WithDefaultServer() DBOption {
}
}

func (w *WebsiteRepo) WithType(websiteType string) DBOption {
return func(db *gorm.DB) *gorm.DB {
return db.Where("type = ?", websiteType)
}
}

func (w *WebsiteRepo) Page(page, size int, opts ...DBOption) (int64, []model.Website, error) {
var websites []model.Website
db := getDb(opts...).Model(&model.Website{})
Expand Down
3 changes: 3 additions & 0 deletions agent/app/service/website.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ func (w WebsiteService) PageWebsite(req request.WebsiteSearch) (int64, []respons
if req.WebsiteGroupID != 0 {
opts = append(opts, websiteRepo.WithGroupID(req.WebsiteGroupID))
}
if req.Type != "" {
opts = append(opts, websiteRepo.WithType(req.Type))
}
total, websites, err := websiteRepo.Page(req.Page, req.PageSize, opts...)
if err != nil {
return 0, nil, err
Expand Down
24 changes: 24 additions & 0 deletions frontend/src/global/mimetype.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,3 +367,27 @@ export const StatusStrategy = [
value: 'backup',
},
];

export const WebsiteTypes = [
{
label: i18n.global.t('website.deployment'),
value: 'deployment',
},
{
label: i18n.global.t('runtime.runtime'),
value: 'runtime',
},

{
label: i18n.global.t('website.proxy'),
value: 'proxy',
},
{
label: i18n.global.t('website.static'),
value: 'static',
},
{
label: i18n.global.t('website.subsite'),
value: 'subsite',
},
];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code appears clean and well structured with appropriate comments. The changes made to WebsiteTypes are consistent with existing patterns used in the other arrays. No significant errors or performance optimizations seem necessary here.

28 changes: 2 additions & 26 deletions frontend/src/views/website/website/create/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,7 @@
<DrawerPro v-model="open" :header="$t('website.create')" size="large" @close="handleClose">
<template #buttons>
<span class="drawer-header-button">
<template
v-for="item in [
{
label: i18n.global.t('website.deployment'),
value: 'deployment',
},
{
label: i18n.global.t('runtime.runtime'),
value: 'runtime',
},

{
label: i18n.global.t('website.proxy'),
value: 'proxy',
},
{
label: i18n.global.t('website.static'),
value: 'static',
},
{
label: i18n.global.t('website.subsite'),
value: 'subsite',
},
]"
:key="item.value"
>
<template v-for="item in WebsiteTypes" :key="item.value">
<el-button
:class="website.type === item.value ? 'active-button' : ''"
@click="changeType(item.value)"
Expand Down Expand Up @@ -572,6 +547,7 @@ import { dateFormatSimple, getProvider, getAccountName } from '@/utils/util';
import { Website } from '@/api/interface/website';
import DomainCreate from '@/views/website/website/domain-create/index.vue';
import { getPathByType } from '@/api/modules/files';
import { WebsiteTypes } from '@/global/mimetype';

const websiteForm = ref<FormInstance>();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The provided code snippet contains some stylistic choices that could be improved for readability and maintainability, particularly regarding comments, formatting, and type imports. Here are a few recommendations:

Improvements

  1. Consistently Use PascalCase: Ensure consistent use of camelCase or PascalCase throughout the file.

  2. Import Statements: If WebsiteTypes is imported within the same module or if it's part of global configuration/constants, remove the need to import it multiple times. However, since you've mentioned importing it locally in this snippet, the issue doesn't apply here specifically but should be avoided elsewhere.

  3. Code Formatting:

    • Add indentation levels more consistently (e.g., using two spaces instead of three).
    • Proper alignment and spacing after commas in array initializations.
  4. Variable Declaration Consistency: Maintain consistency with variable declarations and types where applicable.

Here’s the slightly cleaned-up version of your code:

@@ -2,32 +2,7 @@
 <DrawerPro v-model="open" :header="$t('website.create')" size="large" @close="handleClose">
     <template #buttons>
         <span class="drawer-header-button">
-            <template 
-                v-for="(item) in (
-                    [
-                        {
-                            label: $t('website.deployment'), 
-                            value: 'deployment'
-                        },
-                        {
-                            label: $t('runtime.runtime'), 
-                            value: 'runtime'
-                        },
-                        {
-                            label: $t('website.proxy'), 
-                            value: 'proxy'
-                        },
-                        {
-                            label: $t('website.static'), 
-                            value: 'static'
-                        },
-                        {
-                            label: $t('website.subsite'), 
-                            value: 'subsite'
-                        }
-                    ]
-                )"
-                :key="item.value"
-           >        
+              <template v-for="(item) in WebsiteTypes" :key="item.value">
                   <el-button
                       :class="
                           `${website.type === item.value ? 'active-button' : ''}` 
                       "
                       @click="changeType(item.value)"
                 />
             </template>
         </span>
@@ -572,7 +549,8 @@ import { dateFormatSimple, getProvider, getAccountName } from '@/utils/util';

 import { FormInstance } from "element-plus"; // Replace with correct import statement if needed

import DomainCreate from "@/views/website/website/domain-create/index.vue";
import { getPathByType } from '@/api/modules/files';
-import { WebsiteTypes } from '@/global/mimetype'; // Assuming WebsiteTypes is globally accessible

const websiteForm = ref<FormInstance>();

These changes improve overall clarity and maintainability while adhering to best practices in JavaScript programming.

Expand Down
12 changes: 12 additions & 0 deletions frontend/src/views/website/website/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@
</el-button>
</template>
<template v-if="!openNginxConfig && nginxIsExist" #rightToolBar>
<el-select class="p-w-200" v-model="req.type" @change="search()" :disabled="nginxStatus != 'Running'">
<template #prefix>{{ $t('commons.table.type') }}</template>
<el-option :label="$t('commons.table.all')" :value="''"></el-option>
<el-option
v-for="item in WebsiteTypes"
:label="item.label"
:value="item.value"
:key="item.value"
></el-option>
</el-select>
<el-select
v-model="req.websiteGroupId"
@change="search()"
Expand Down Expand Up @@ -265,6 +275,7 @@ import { useI18n } from 'vue-i18n';
import { getAgentGroupList } from '@/api/modules/group';
import { Group } from '@/api/interface/group';
import { GlobalStore } from '@/store';
import { WebsiteTypes } from '@/global/mimetype';
const globalStore = GlobalStore();

const shortcuts = [
Expand Down Expand Up @@ -317,6 +328,7 @@ let req = reactive({
orderBy: 'createdAt',
order: 'null',
websiteGroupId: 0,
type: '',
});
const mobile = computed(() => {
return globalStore.isMobile();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There appear to be minor formatting changes and an addition to the code snippet. Here are my observations:

  1. Formatting Changes: The line const shortcuts = [...] is now indented differently at the beginning, which might affect its functionality slightly in certain contexts but should not cause any significant issues.

  2. New Variable Declaration: There is a new WebsiteTypes array being declared with type annotations: let WebsiteTypes: unknown[]. This is added within the function scope where it will be used without immediately assigning a value. This can lead to unexpected behavior if this list doesn't contain data before usage, so it's generally recommended to initialize such lists explicitly with some default values or empty arrays until they're populated with actual data.

Considering further improvement points based on best practices:

  1. Global Constant Initialization: It would improve readability if you declare constants or variables that won't change throughout the lifecycle of the component outside the initialization block (const globalStore = GlobalStore();). For example, defining them at top level could help avoid redundant assignments later in the script (though TypeScript does not prevent overwriting unless marked as constant).

Overall, this code looks functional and well-documented for Vue.js development with typescript support, making use of Vuex for state management.

Expand Down
Loading