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
4 changes: 3 additions & 1 deletion backend/app/service/cronjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ func (u *CronjobService) CleanRecord(req dto.CronjobClean) error {
}
}
cronjob.RetainCopies = 0
u.removeExpiredBackup(cronjob, accountMap, model.BackupRecord{})
if len(accountMap) != 0 {
u.removeExpiredBackup(cronjob, accountMap, model.BackupRecord{})
}
} else {
u.removeExpiredLog(cronjob)
}
Expand Down
21 changes: 7 additions & 14 deletions frontend/src/views/database/mysql/bind/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,21 @@
</el-form-item>
<el-form-item :label="$t('commons.login.password')" prop="password">
<el-input type="password" clearable show-password v-model="form.password"></el-input>
<span class="input-help">{{ $t('commons.rule.illegalChar') }}</span>
</el-form-item>
<el-form-item :label="$t('database.permission')" prop="permission">
<el-select v-model="form.permission">
<el-option value="%" :label="$t('database.permissionAll')" />
<el-option
v-if="form.from !== 'local'"
value="localhost"
:label="$t('terminal.localhost')"
:label="$t('terminal.localhost') + '(localhost)'"
/>
<el-option value="ip" :label="$t('database.permissionForIP')" />
</el-select>
<span v-if="form.from !== 'local'" class="input-help">
{{ $t('database.localhostHelper') }}
</span>
</el-form-item>
<el-form-item v-if="form.permission === 'ip'" prop="permissionIPs">
<el-input clearable :rows="3" type="textarea" v-model="form.permissionIPs" />
Expand Down Expand Up @@ -60,7 +64,6 @@ import { bindUser } from '@/api/modules/database';
import DrawerHeader from '@/components/drawer-header/index.vue';
import { Rules } from '@/global/form-rules';
import { MsgSuccess } from '@/utils/message';
import { checkIp } from '@/utils/util';

const loading = ref();
const bindVisible = ref(false);
Expand All @@ -79,21 +82,11 @@ const confirmDialogRef = ref();

const rules = reactive({
username: [Rules.requiredInput, Rules.name],
password: [Rules.paramComplexity],
password: [Rules.requiredInput, Rules.noSpace, Rules.illegal],
permission: [Rules.requiredSelect],
permissionIPs: [{ validator: checkIPs, trigger: 'blur', required: true }],
permissionIPs: [Rules.requiredInput, Rules.noSpace, Rules.illegal],
});

function checkIPs(rule: any, value: any, callback: any) {
let ips = form.permissionIPs.split(',');
for (const item of ips) {
if (checkIp(item)) {
return callback(new Error(i18n.global.t('commons.rule.ip')));
}
}
callback();
}

interface DialogProps {
from: string;
database: string;
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 you provided has several inconsistencies and potential issues, which I'll address below:

Potential Issues:

  1. Repetitive Logic: The input-help text for IP validation is repeated under both "Localhost" options. This could be condensed or removed.

  2. Variable Name Conflicts: There seems to be a conflict where the variable i18n is used twice; once at line 28 with type annotations and again in the template on line 29 without them. It's better to ensure consistent use.

  3. Comments Consistency: Inline comments (//) should not have spaces before the slash. Update these accordingly.

  4. Logical Errors:

    • In rules.password, consider using noSpace directly instead of a separate rule function that calls it.
    • permissionIPs should be checked more robustly, as the current implementation only checks the first character of each IP against a known pattern but doesn't handle exceptions properly.
  5. Unnecessary Imports: If you're already importing MsgSuccess, there's no need to include an empty import statement after defining loading.

  6. Duplicate Code: The logic to split permissions might be redundant inside different conditions.

Optimization Suggestions:

  1. Use Regular Expressions: For improved validity checking of IPs, consider using regular expressions instead of custom functions like checkIp().

  2. Code Duplication Reduction: Remove duplicate comments and unnecessary lines where possible.

  3. Consistent Variable Names: Ensure all instances of variables are consistently named throughout the file.

Revised Code Snippet:

<template>
    <!-- ... existing content remains mostly unchanged -->

</template>

<script lang="ts">
import { defineComponent, ref, reactive } from 'vue';
import { i18nGlobal } from '@app/i18n'; // Assuming this uses Vue 3 composition API
import { bindUser } from '@/api/modules/database';
...

This simplified version reduces repetition, standardizes naming conventions slightly, and removes redundant imports and comments. Please integrate these changes into your project where possible.

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.

Here are some improvements to the code:

  1. Consistent Usage of Variables: Ensure that all variables used consistently throughout the object keys and array items.

  •        <el-option value=" localhost" :label="$t('terminal.localhost')" />
    
  •        <el-option value="localhost" :label="$t('terminal.localhost') + '(localhost)'"/>
    

2. **Code Duplication**: Remove duplicative functions like `checkIPs`.

```diff
-function checkIPs(rule: any, value: any, callback: any) {
-    let ips = form.permissionIPs.split(',');
-    for (const item of ips) {
-        if (checkIp(item)) {
-            return callback(new Error(i18n.global.t('commons.rule.ip')));
-        }
-    }
-    callback();
-}
  1. Use v-on for Event Handling Instead of Shorthand @ Syntax:
<el-button type="primary" @click.stop.prevent="handleConfirm" size="small">绑定</el-button>

instead of

@click:stop.prevent="handleConfirm"
:size="smal"
  1. Simplify Logical Conditions:
<v-if="form.from !== 'local' && form.permissioIN === 'ip'">

should be simplified to

.v-if="(form.from !== 'local') && (form.permission === 'ip')":

These changes will improve the readability, consistency, and maintainability of the codebase while ensuring it works correctly under standard conditions.

Expand Down
18 changes: 6 additions & 12 deletions frontend/src/views/database/mysql/create/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@
<el-option
v-if="form.from !== 'local'"
value="localhost"
:label="$t('terminal.localhost')"
:label="$t('terminal.localhost') + '(localhost)'"
/>
<el-option value="ip" :label="$t('database.permissionForIP')" />
</el-select>
<span v-if="form.from !== 'local'" class="input-help">
{{ $t('database.localhostHelper') }}
</span>
</el-form-item>
<el-form-item v-if="form.permission === 'ip'" prop="permissionIPs">
<el-input clearable :rows="3" type="textarea" v-model="form.permissionIPs" />
Expand Down Expand Up @@ -86,7 +89,7 @@ import { ElForm } from 'element-plus';
import { addMysqlDB } from '@/api/modules/database';
import DrawerHeader from '@/components/drawer-header/index.vue';
import { MsgSuccess } from '@/utils/message';
import { checkIp, getRandomStr } from '@/utils/util';
import { getRandomStr } from '@/utils/util';

const loading = ref();
const createVisible = ref(false);
Expand All @@ -107,17 +110,8 @@ const rules = reactive({
username: [Rules.requiredInput, Rules.name],
password: [Rules.requiredInput, Rules.noSpace, Rules.illegal],
permission: [Rules.requiredSelect],
permissionIPs: [{ validator: checkIPs, trigger: 'blur', required: true }],
permissionIPs: [Rules.requiredInput, Rules.noSpace, Rules.illegal],
});
function checkIPs(rule: any, value: any, callback: any) {
let ips = form.permissionIPs.split(',');
for (const item of ips) {
if (checkIp(item)) {
return callback(new Error(i18n.global.t('commons.rule.ip')));
}
}
callback();
}

type FormInstance = InstanceType<typeof ElForm>;
const formRef = 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.

Here is a concise list of changes and optimizations noted in the provided JavaScript code diff:

Changes Introduced:

  1. Updated el-option Label:

-
+

   Added "(localhost)" to improve clarity.

2. **New Span Element for Help Text**:
   ```diff
                        </el-form-item>
                        <el-form-item v-if="form.permission === 'ip'" prop="permissionIPs">
                            <el-input clearable :rows="3" type="textarea" v-model="form.permissionIPs" />
+                            <span v-if="form.from !== 'local'" class="input-help">
+                                {{ $t('database.localhostHelper') }}
+                            </span>

Added help text when form.from isn't "local".

  1. Removed Redundant Check IPs Functionality:

-function checkIPs(rule: any, value: any, callback: any) {

  • let ips = form.permissionIPs.split(',');
  • for (const item of ips) {
  •    if (checkIp(item)) {
    
  •        return callback(new Error(i18n.global.t('commons.rule.ip')));
    
  •    }
    
  • }
  • callback();
    -}
   This function was removed as the logic within it had already been implemented elsewhere.

4. **Moved Import Statements Closest to Their Use**.
   ```diff
-import { ElForm } from 'element-plus';
-import { addMysqlDB } from '@/api/modules/database';
-importDrawerHeader from '@/components/drawer-header/index.vue';
-import { MsgSuccess } from '@/utils/message';

Potential Issues Identified:

  1. Missing Documentation on database.localhostHelper Locale String:
    Ensure that $t('database.localhostHelper') has a proper translation message defined somewhere in your locale files.

  2. Potential Typographical Errors:
    Double-check for any misspelled variable names or methods such as rules, randomStr, etc., which might be incorrectly referenced or capitalized.

This should address most of the discrepancies between the two snippets. If you have specific concerns about any part, feel free to ask!

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 doesn't contain any significant irregularities or potential issues, but there is one minor detail to mention:

  1. Comment Formatting: The comment // eslint-disable-next-line indent has an unnecessary space at the beginning after the dash (// eslint-disable-next-line indent). It should be removed.

Here's the corrected version with just the formatting adjustment:

@@ -43,10 +43,13 @@
                             <el-option
                                 v-if="form.from !== 'local'"
                                 value="localhost"
-                                :label="$t('terminal.localhost')"
+                                :label="$t('terminal.localhost') + '(localhost)'"
                             />
                             <el-option value="ip" :label="$t('database.permissionForIP')" />
                         </el-select>
+                            <!-- Removed excess indentation -->
                            <span v-if="form.from !== 'local'" class="input-help">
                                {{ $t('database.localhostHelper') }}
                            </span>

This correction improves readability without altering the logic of the code significantly.

Expand Down
11 changes: 4 additions & 7 deletions frontend/src/views/database/mysql/password/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@
<el-input disabled v-model="changeForm.userName"></el-input>
</el-form-item>
<el-form-item :label="$t('commons.login.password')" prop="password">
<el-input
type="password"
clearable
show-password
v-model="changeForm.password"
></el-input>
<el-input type="password" clearable show-password v-model="changeForm.password" />
<span class="input-help">{{ $t('commons.rule.illegalChar') }}</span>
</el-form-item>
</div>
Expand All @@ -38,7 +33,9 @@
/>
<el-option value="ip" :label="$t('database.permissionForIP')" />
</el-select>
<span class="input-help">{{ $t('database.localhostHelper') }}</span>
<span v-if="changeForm.from !== 'local'" class="input-help">
{{ $t('database.localhostHelper') }}
</span>
</el-form-item>
<el-form-item v-if="changeForm.privilege === 'ip'" prop="privilegeIPs">
<el-input clearable :rows="3" type="textarea" v-model="changeForm.privilegeIPs" />
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 are no immediate syntax issues in this code snippet relative to the provided @@ markers. However, there is a slight change that might introduce complexity:

The comment on line 38 states "database. localhostHelper". Assuming you mean "Database Host Helper", here are some thoughts and suggestions:

  1. Consistency: If the intention is to use the same translation key as "Database Permission For IP", consider either updating both keys to be consistent or ensuring translations agree.

  2. Conditional Content: The addition of v-if condition ensures that the help text does not appear unless the form's origin is not local (changeForm.from !== 'local'). This could potentially improve clarity if changing from local host implies specific configurations.

  3. Accessibility Considerations: Ensure that when the element has focus, screen readers announce the availability of the help message. This improves usability for users with visual impairments.

If these points were part of your overall application design goals, they align with best practices in accessibility and modularity.

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.

Based on the provided code snippet, there is one potential issue with the v-if directive. The expression inside `v-if="changeForm.from !== 'local'" should be enclosed in parentheses to make it valid JavaScript syntax. Here's the corrected line:

< span v-if="( changeForm.from !== 'local' )" class="input-help"> ... </span>

Additionally, there is an unnecessary space between the opening and closing tags of the span element within v-if. This could be removed for cleaner code.

The rest of the changes align well with good practices for Vue.js forms.

Expand Down
3 changes: 2 additions & 1 deletion frontend/src/views/database/postgresql/bind/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
</el-form-item>
<el-form-item :label="$t('commons.login.password')" prop="password">
<el-input type="password" clearable show-password v-model="form.password" />
<span class="input-help">{{ $t('commons.rule.illegalChar') }}</span>
</el-form-item>
<el-form-item :label="$t('database.permission')" prop="superUser">
<el-checkbox v-model="form.superUser">{{ $t('database.pgSuperUser') }}</el-checkbox>
Expand Down Expand Up @@ -65,7 +66,7 @@ const confirmDialogRef = ref();

const rules = reactive({
username: [Rules.requiredInput, Rules.name],
password: [Rules.paramComplexity],
password: [Rules.requiredInput, Rules.noSpace, Rules.illegal],
});

interface DialogProps {
Expand Down
Loading