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
2 changes: 1 addition & 1 deletion frontend/src/api/modules/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export const computeDirSize = (params: File.DirSizeReq) => {
};

export const fileWgetKeys = () => {
return http.get<File.FileKeys>('files//wget/process/keys');
return http.get<File.FileKeys>('files/wget/process/keys');
};

export const getRecycleList = (params: ReqPage) => {
Expand Down
24 changes: 24 additions & 0 deletions frontend/src/utils/runtime.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Runtime } from '@/api/interface/runtime';

export function disabledButton(row: Runtime.Runtime, type: string): boolean {
switch (type) {
case 'stop':
return row.status === 'Recreating' || row.status === 'Stopped' || row.status === 'Building';
case 'start':
return (
row.status === 'Starting' ||
row.status === 'Recreating' ||
row.status === 'Running' ||
row.status === 'Building'
);
case 'restart':
return row.status === 'Recreating' || row.status === 'Building';
case 'edit':
return row.status === 'Recreating' || row.status === 'Building';
case 'extension':
case 'config':
return row.status != 'Running';
default:
return false;
}
}
Copy link
Member

Choose a reason for hiding this comment

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

The code seems well-structured and does not contain any obvious errors nor significant inefficiencies.

There isn't much room for improvement or suggestion without more context, however, to make specific optimizations.

However, this function could benefit from using reduce if it's being used frequently in conditional branches. It would reduce redundancy, increase readability, and potentially optimize performance under certain circumstances:

switch (type) {
    case 'stop': 
        return row.status === 'Recreating' || row.status === 'Stopped' || row.status === 'Building';
    // ...rest of cases...
    // ...default: return false; 
}

It'll be important to consider that the switch statement can become redundant with a loop where conditions match exactly like below:

case 'stop':
if (row.status === 'Recreating' || row.status === 'Stopped' || row.status === 'Building') return true;
return false;
break;

// rest of cases

default:
...rest of cases...
return false;
}

9 changes: 5 additions & 4 deletions frontend/src/views/website/runtime/dotnet/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ import AppResources from '@/views/website/runtime/php/check/index.vue';
import { ElMessageBox } from 'element-plus';
import { GlobalStore } from '@/store';
import RuntimeStatus from '@/views/website/runtime/components/runtime-status.vue';
import { disabledButton } from '@/utils/runtime';

let timer: NodeJS.Timer | null = null;
const loading = ref(false);
Expand Down Expand Up @@ -142,7 +143,7 @@ const buttons = [
operateRuntime('down', row.id);
},
disabled: function (row: Runtime.Runtime) {
return row.status === 'recreating' || row.status === 'stopped';
return disabledButton(row, 'stop');
},
},
{
Expand All @@ -151,7 +152,7 @@ const buttons = [
operateRuntime('up', row.id);
},
disabled: function (row: Runtime.Runtime) {
return row.status === 'starting' || row.status === 'recreating' || row.status === 'running';
return disabledButton(row, 'start');
},
},
{
Expand All @@ -160,7 +161,7 @@ const buttons = [
operateRuntime('restart', row.id);
},
disabled: function (row: Runtime.Runtime) {
return row.status === 'recreating';
return disabledButton(row, 'restart');
},
},
{
Expand All @@ -169,7 +170,7 @@ const buttons = [
openDetail(row);
},
disabled: function (row: Runtime.Runtime) {
return row.status === 'recreating';
return disabledButton(row, 'edit');
},
},
{
Expand Down
9 changes: 5 additions & 4 deletions frontend/src/views/website/runtime/go/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ import PortJumpDialog from '@/components/port-jump/index.vue';
import AppResources from '@/views/website/runtime/php/check/index.vue';
import { ElMessageBox } from 'element-plus';
import RuntimeStatus from '@/views/website/runtime/components/runtime-status.vue';
import { disabledButton } from '@/utils/runtime';

let timer: NodeJS.Timer | null = null;
const loading = ref(false);
Expand Down Expand Up @@ -136,7 +137,7 @@ const buttons = [
operateRuntime('down', row.id);
},
disabled: function (row: Runtime.Runtime) {
return row.status === 'recreating' || row.status === 'stopped';
return disabledButton(row, 'stop');
},
},
{
Expand All @@ -145,7 +146,7 @@ const buttons = [
operateRuntime('up', row.id);
},
disabled: function (row: Runtime.Runtime) {
return row.status === 'starting' || row.status === 'recreating' || row.status === 'running';
return disabledButton(row, 'start');
},
},
{
Expand All @@ -154,7 +155,7 @@ const buttons = [
operateRuntime('restart', row.id);
},
disabled: function (row: Runtime.Runtime) {
return row.status === 'recreating';
return disabledButton(row, 'restart');
},
},
{
Expand All @@ -163,7 +164,7 @@ const buttons = [
openDetail(row);
},
disabled: function (row: Runtime.Runtime) {
return row.status === 'recreating';
return disabledButton(row, 'edit');
},
},
{
Expand Down
9 changes: 5 additions & 4 deletions frontend/src/views/website/runtime/java/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ import PortJumpDialog from '@/components/port-jump/index.vue';
import AppResources from '@/views/website/runtime/php/check/index.vue';
import { ElMessageBox } from 'element-plus';
import RuntimeStatus from '@/views/website/runtime/components/runtime-status.vue';
import { disabledButton } from '@/utils/runtime';

let timer: NodeJS.Timer | null = null;
const loading = ref(false);
Expand Down Expand Up @@ -136,7 +137,7 @@ const buttons = [
operateRuntime('down', row.id);
},
disabled: function (row: Runtime.Runtime) {
return row.status === 'recreating' || row.status === 'stopped';
return disabledButton(row, 'stop');
},
},
{
Expand All @@ -145,7 +146,7 @@ const buttons = [
operateRuntime('up', row.id);
},
disabled: function (row: Runtime.Runtime) {
return row.status === 'starting' || row.status === 'recreating' || row.status === 'running';
return disabledButton(row, 'start');
},
},
{
Expand All @@ -154,7 +155,7 @@ const buttons = [
operateRuntime('restart', row.id);
},
disabled: function (row: Runtime.Runtime) {
return row.status === 'recreating';
return disabledButton(row, 'restart');
},
},
{
Expand All @@ -163,7 +164,7 @@ const buttons = [
openDetail(row);
},
disabled: function (row: Runtime.Runtime) {
return row.status === 'recreating';
return disabledButton(row, 'edit');
},
},
{
Expand Down
11 changes: 6 additions & 5 deletions frontend/src/views/website/runtime/node/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ import PortJumpDialog from '@/components/port-jump/index.vue';
import AppResources from '@/views/website/runtime/php/check/index.vue';
import { ElMessageBox } from 'element-plus';
import RuntimeStatus from '@/views/website/runtime/components/runtime-status.vue';
import { disabledButton } from '@/utils/runtime';

let timer: NodeJS.Timer | null = null;
const loading = ref(false);
Expand Down Expand Up @@ -139,7 +140,7 @@ const buttons = [
openModules(row);
},
disabled: function (row: Runtime.Runtime) {
return row.status === 'recreating' || row.status === 'stopped';
return disabledButton(row, 'stop');
},
},
{
Expand All @@ -148,7 +149,7 @@ const buttons = [
operateRuntime('down', row.id);
},
disabled: function (row: Runtime.Runtime) {
return row.status === 'recreating' || row.status === 'stopped';
return disabledButton(row, 'stop');
},
},
{
Expand All @@ -157,7 +158,7 @@ const buttons = [
operateRuntime('up', row.id);
},
disabled: function (row: Runtime.Runtime) {
return row.status === 'starting' || row.status === 'recreating' || row.status === 'running';
return disabledButton(row, 'start');
},
},
{
Expand All @@ -166,7 +167,7 @@ const buttons = [
operateRuntime('restart', row.id);
},
disabled: function (row: Runtime.Runtime) {
return row.status === 'recreating';
return disabledButton(row, 'restart');
},
},
{
Expand All @@ -175,7 +176,7 @@ const buttons = [
openDetail(row);
},
disabled: function (row: Runtime.Runtime) {
return row.status === 'recreating';
return disabledButton(row, 'edit');
},
},
{
Copy link
Member

Choose a reason for hiding this comment

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

I'm sorry, but I need a specific code snippet to analyze. Please provide more details about the code you are referring to or share the entire codebase with its contents so that I can accurately review it for you.

Expand Down
23 changes: 8 additions & 15 deletions frontend/src/views/website/runtime/php/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ import ComposeLogs from '@/components/compose-log/index.vue';
import Config from '@/views/website/runtime/php/config/index.vue';
import Supervisor from '@/views/website/runtime/php/supervisor/index.vue';
import RuntimeStatus from '@/views/website/runtime/components/runtime-status.vue';
import { disabledButton } from '@/utils/runtime';

const paginationConfig = reactive({
cacheSizeKey: 'runtime-page-size',
Expand Down Expand Up @@ -160,7 +161,7 @@ const buttons = [
openExtensionsManagement(row);
},
disabled: function (row: Runtime.Runtime) {
return row.status != 'running';
return disabledButton(row, 'extension');
},
},
{
Expand All @@ -169,7 +170,7 @@ const buttons = [
operateRuntime('down', row.id);
},
disabled: function (row: Runtime.Runtime) {
return row.status === 'recreating' || row.status === 'stopped' || row.status === 'building';
return disabledButton(row, 'stop');
},
},
{
Expand All @@ -178,12 +179,7 @@ const buttons = [
operateRuntime('up', row.id);
},
disabled: function (row: Runtime.Runtime) {
return (
row.status === 'starting' ||
row.status === 'recreating' ||
row.status === 'running' ||
row.status === 'building'
);
return disabledButton(row, 'start');
},
},
{
Expand All @@ -192,7 +188,7 @@ const buttons = [
operateRuntime('restart', row.id);
},
disabled: function (row: Runtime.Runtime) {
return row.status === 'recreating' || row.status === 'building';
return disabledButton(row, 'restart');
},
},
{
Expand All @@ -201,7 +197,7 @@ const buttons = [
openDetail(row);
},
disabled: function (row: Runtime.Runtime) {
return row.status === 'building';
return disabledButton(row, 'edit');
},
},
{
Expand All @@ -210,7 +206,7 @@ const buttons = [
openConfig(row);
},
disabled: function (row: Runtime.Runtime) {
return row.status === 'building';
return disabledButton(row, 'config');
},
},
{
Expand All @@ -219,14 +215,11 @@ const buttons = [
openSupervisor(row);
},
disabled: function (row: Runtime.Runtime) {
return row.status === 'building';
return disabledButton(row, 'config');
},
},
{
label: i18n.global.t('commons.button.delete'),
disabled: function (row: Runtime.Runtime) {
return row.status === 'building';
},
click: function (row: Runtime.Runtime) {
openDelete(row);
},
Copy link
Member

Choose a reason for hiding this comment

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

This looks like a JavaScript code snippet related to web components. Without actual source context and detailed code analysis, it's tough to provide specific improvements or suggestions directly. However, if we're talking about efficiency in this context:

  • It would be useful to optimize loops and reduce redundancy.
  • Check that there is no duplicate configuration data.

As an example of improved optimization within these sections, you might refactor the "disabled" state checks into utility functions rather than deep nesting logic inside each element declaration. This could improve maintainability when dealing with complex configurations later on.

Expand Down
9 changes: 5 additions & 4 deletions frontend/src/views/website/runtime/python/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ import PortJumpDialog from '@/components/port-jump/index.vue';
import AppResources from '@/views/website/runtime/php/check/index.vue';
import { ElMessageBox } from 'element-plus';
import RuntimeStatus from '@/views/website/runtime/components/runtime-status.vue';
import { disabledButton } from '@/utils/runtime';

let timer: NodeJS.Timer | null = null;
const loading = ref(false);
Expand Down Expand Up @@ -136,7 +137,7 @@ const buttons = [
operateRuntime('down', row.id);
},
disabled: function (row: Runtime.Runtime) {
return row.status === 'recreating' || row.status === 'stopped';
return disabledButton(row, 'stop');
},
},
{
Expand All @@ -145,7 +146,7 @@ const buttons = [
operateRuntime('up', row.id);
},
disabled: function (row: Runtime.Runtime) {
return row.status === 'starting' || row.status === 'recreating' || row.status === 'running';
return disabledButton(row, 'start');
},
},
{
Expand All @@ -154,7 +155,7 @@ const buttons = [
operateRuntime('restart', row.id);
},
disabled: function (row: Runtime.Runtime) {
return row.status === 'recreating';
return disabledButton(row, 'restart');
},
},
{
Expand All @@ -163,7 +164,7 @@ const buttons = [
openDetail(row);
},
disabled: function (row: Runtime.Runtime) {
return row.status === 'recreating';
return disabledButton(row, 'edit');
},
},
{
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/views/website/website/create/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ const runtimeResource = ref('appstore');
const initRuntimeReq = () => ({
page: 1,
pageSize: 100,
status: 'running',
status: 'Running',
type: 'php',
});
const runtimeReq = ref<Runtime.RuntimeReq>(initRuntimeReq());
Expand Down
Loading