mirror of
https://github.com/jumpserver/lina.git
synced 2025-05-05 14:46:37 +00:00
perf: Optimized operation logic
This commit is contained in:
parent
d5d9f8024c
commit
c6568f57fe
src/views/ops/Adhoc
@ -34,8 +34,10 @@
|
|||||||
<QuickJobTerm
|
<QuickJobTerm
|
||||||
ref="xterm"
|
ref="xterm"
|
||||||
:show-tool-bar="true"
|
:show-tool-bar="true"
|
||||||
|
:select-assets="selectAssets"
|
||||||
:xterm-config="xtermConfig"
|
:xterm-config="xtermConfig"
|
||||||
:execution-info="executionInfo"
|
:execution-info="executionInfo"
|
||||||
|
@view-assets="viewConfirmRunAssets"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div style="display: flex;margin-top:10px;justify-content: space-between" />
|
<div style="display: flex;margin-top:10px;justify-content: space-between" />
|
||||||
@ -47,6 +49,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import $ from '@/utils/jquery-vendor.js'
|
import $ from '@/utils/jquery-vendor.js'
|
||||||
|
import _isequal from 'lodash.isequal'
|
||||||
import AssetTreeTable from '@/components/Apps/AssetTreeTable'
|
import AssetTreeTable from '@/components/Apps/AssetTreeTable'
|
||||||
import QuickJobTerm from '@/views/ops/Adhoc/components/QuickJobTerm.vue'
|
import QuickJobTerm from '@/views/ops/Adhoc/components/QuickJobTerm.vue'
|
||||||
import CodeEditor from '@/components/Form/FormFields/CodeEditor'
|
import CodeEditor from '@/components/Form/FormFields/CodeEditor'
|
||||||
@ -325,7 +328,9 @@ export default {
|
|||||||
error: [],
|
error: [],
|
||||||
runnable: [],
|
runnable: [],
|
||||||
skipped: []
|
skipped: []
|
||||||
}
|
},
|
||||||
|
selectAssets: [],
|
||||||
|
lastRequestPayload: null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@ -455,6 +460,12 @@ export default {
|
|||||||
})
|
})
|
||||||
return { hosts, nodes }
|
return { hosts, nodes }
|
||||||
},
|
},
|
||||||
|
shouldReRequest(payload) {
|
||||||
|
if (!this.lastRequestPayload) return true
|
||||||
|
const current = _.omit(payload, ['args'])
|
||||||
|
const last = _.omit(this.lastRequestPayload, ['args'])
|
||||||
|
return !_isequal(current, last)
|
||||||
|
},
|
||||||
execute() {
|
execute() {
|
||||||
// const size = 'rows=' + this.xterm.rows + '&cols=' + this.xterm.cols
|
// const size = 'rows=' + this.xterm.rows + '&cols=' + this.xterm.cols
|
||||||
const { hosts, nodes } = this.getSelectedNodesAndHosts()
|
const { hosts, nodes } = this.getSelectedNodesAndHosts()
|
||||||
@ -471,13 +482,22 @@ export default {
|
|||||||
this.$message.error(this.$tc('RequiredRunas'))
|
this.$message.error(this.$tc('RequiredRunas'))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.$axios.post('/api/v1/ops/inventory/classified-hosts/', {
|
const payload = {
|
||||||
assets: hosts,
|
assets: hosts,
|
||||||
nodes: nodes,
|
nodes: nodes,
|
||||||
module: this.module,
|
module: this.module,
|
||||||
args: this.command,
|
args: this.command,
|
||||||
runas: this.runas,
|
runas: this.runas,
|
||||||
runas_policy: this.runasPolicy
|
runas_policy: this.runasPolicy
|
||||||
|
}
|
||||||
|
if (!this.shouldReRequest(payload)) {
|
||||||
|
this.onConfirmRunAsset(this.selectAssets, nodes)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.lastRequestPayload = { ...payload }
|
||||||
|
this.$axios.post('/api/v1/ops/classified-hosts/', {
|
||||||
|
...payload
|
||||||
}).then(data => {
|
}).then(data => {
|
||||||
this.classifiedAssets = data
|
this.classifiedAssets = data
|
||||||
if (this.classifiedAssets.error.length === 0) {
|
if (this.classifiedAssets.error.length === 0) {
|
||||||
@ -514,6 +534,10 @@ export default {
|
|||||||
this.writeExecutionOutput()
|
this.writeExecutionOutput()
|
||||||
this.setBtn()
|
this.setBtn()
|
||||||
})
|
})
|
||||||
|
this.selectAssets = assets
|
||||||
|
},
|
||||||
|
viewConfirmRunAssets() {
|
||||||
|
this.showConfirmRunAssetsDialog = true
|
||||||
},
|
},
|
||||||
stop() {
|
stop() {
|
||||||
stopJob({ task_id: this.currentTaskId }).then(() => {
|
stopJob({ task_id: this.currentTaskId }).then(() => {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<Dialog
|
<Dialog
|
||||||
:title="$t('ConfirmRunningAssets')"
|
:title="$t('ConfirmRunningAssets')"
|
||||||
:visible.sync="visible"
|
:visible.sync="iVisible"
|
||||||
:show-buttons="true"
|
:show-buttons="true"
|
||||||
:show-confirm="true"
|
:show-confirm="true"
|
||||||
:show-cancel="true"
|
:show-cancel="true"
|
||||||
@ -48,7 +48,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<div class="selected-count">{{ $t('AssetsSelected', {count: selectedAssets.length}) }}</div>
|
<div class="selected-count">{{ selectedAssets.length }}{{ $t('AssetsSelected') }}</div>
|
||||||
</div>
|
</div>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
</template>
|
</template>
|
||||||
@ -80,6 +80,14 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
iVisible: {
|
||||||
|
set(val) {
|
||||||
|
this.$emit('update:visible', val)
|
||||||
|
},
|
||||||
|
get() {
|
||||||
|
return this.visible
|
||||||
|
}
|
||||||
|
},
|
||||||
runnableAssets() {
|
runnableAssets() {
|
||||||
return this.assets.runnable
|
return this.assets.runnable
|
||||||
},
|
},
|
||||||
@ -89,7 +97,7 @@ export default {
|
|||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
visible(val) {
|
visible(val) {
|
||||||
if (val === true) {
|
if (val === true && this.selectedAssets.length === 0) {
|
||||||
this.selectedAssets = this.runnableAssets.map((item) => item.id)
|
this.selectedAssets = this.runnableAssets.map((item) => item.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,16 @@
|
|||||||
v-if="executionInfo.status"
|
v-if="executionInfo.status"
|
||||||
class="header-status"
|
class="header-status"
|
||||||
>
|
>
|
||||||
|
<span class="status-item">
|
||||||
|
<el-link
|
||||||
|
@click="viewConfirmRunAssets"
|
||||||
|
>
|
||||||
|
<span>{{ selectAssets.length }}</span>
|
||||||
|
</el-link>
|
||||||
|
<span style="display: inline-block;" @click="viewConfirmRunAssets">
|
||||||
|
{{ $t('AssetsSelected') }}
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
<span class="status-item">
|
<span class="status-item">
|
||||||
<span>{{ $tc('Status') }}: </span>
|
<span>{{ $tc('Status') }}: </span>
|
||||||
<span
|
<span
|
||||||
@ -67,6 +77,10 @@ export default {
|
|||||||
type: Object,
|
type: Object,
|
||||||
// eslint-disable-next-line vue/require-valid-default-prop
|
// eslint-disable-next-line vue/require-valid-default-prop
|
||||||
default: {}
|
default: {}
|
||||||
|
},
|
||||||
|
selectAssets: {
|
||||||
|
type: Array,
|
||||||
|
default: () => []
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
@ -153,6 +167,9 @@ export default {
|
|||||||
this.showScrollButton = true
|
this.showScrollButton = true
|
||||||
this.xterm.scrollToBottom()
|
this.xterm.scrollToBottom()
|
||||||
})
|
})
|
||||||
|
},
|
||||||
|
viewConfirmRunAssets() {
|
||||||
|
this.$emit('view-assets')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user