3
3
<h6 class =" text-center mt-2" >List of Agents</h6 >
4
4
<div class =" card card-style" >
5
5
<div class =" card-body" >
6
- <div v-if =" agentsList .length > 0" class =" card card-table" >
6
+ <div v-if =" rootDomainAgents .length > 0" class =" card card-table" >
7
7
<div class =" row mb-2" >
8
8
<div class =" col-2 border-left-radius border-right text-light-white domain-names-list p-2" v-bind:style =" {'background':color}" > <p class =" ml-2 m-0" v-on:click =" orderByName()" > Name
9
9
<i class =" material-icons right float-right" v-show =" active_arrow_down" >keyboard_arrow_down</i >
17
17
<div class =" col-2 p-2 border-right-radius text-light-white text-center domain-names-list" v-bind:style =" {'background':color}" >
18
18
Actions</div >
19
19
</div >
20
- <div class =" row mb-2" v-for =" item of this.agentsList " :key =" item.id" >
20
+ <div class =" row mb-2" v-for =" item of rootDomainAgents " :key =" item.id" >
21
21
<div class =" col-2 border-left-radius border" >
22
22
<p class =" m-2" > {{item.name}}</p >
23
23
</div >
31
31
</div >
32
32
<div class =" col-2 border border-right-radius text-center" >
33
33
<button v-if =" parseInt(item.status) === parseInt(this.$entityStatus.RUNNING)" type =" button" @click =" selectAgent" class =" color-rgb-0-177-255 agent-border btn create-agent-buttons-main-action m-1 p-0" data-toggle =" modal" data-target =" #agentExecutionModalForm" :data-id =" item.id" :data-name =" item.name" >Running...</button >
34
- <button v-else :disabled =" isRunningAgent !== -1 && isRunningAgent !== parseInt( item.id) " @click = " selectAgent " type =" button" class =" color-rgb-0-177-255 agent-border btn create-agent-buttons-main-action m-1 p-0" data-toggle =" modal" data-target =" #agentExecutionModalForm " :data-id =" item.id" :data-name =" item.name" >Run</button >
34
+ <button v-else :disabled =" isRunningAgent !== -1 && isRunningAgent !== item.id" type =" button" class =" color-rgb-0-177-255 agent-border btn create-agent-buttons-main-action m-1 p-0" data-toggle =" modal" data-target =" #confirmation-before-run-an-agent " :data-id =" item.id" :data-name =" item.name" >Run</button >
35
35
</div >
36
36
<AgentExecution :id-agent =" this.selectedAgentId" :name-agent =" selectedAgentName" />
37
+ <ConfirmationBeforeRunAnAgent @run-agent =" runAgent" :dataId =" item.id" :dataName =" item.name" />
37
38
</div >
38
39
</div >
39
40
<div v-else >
45
46
</div ></div >
46
47
</template >
47
48
<script >
48
- import { mapGetters , mapState , mapMutations } from ' vuex'
49
+ import { mapGetters , mapState , mapMutations , mapActions } from ' vuex'
49
50
import AgentExecution from ' @/components/Target/AgentExecution.vue'
51
+ import ConfirmationBeforeRunAnAgent from ' @/components/Target/ConfirmationBeforeRunAnAgent.vue'
52
+ import { StatusMessageMixin } from ' @/mixins/StatusMessageMixin'
53
+ import jQuery from ' jquery'
50
54
export default {
51
55
name: ' AgentListTable' ,
52
56
components: {
53
- AgentExecution
57
+ AgentExecution,
58
+ ConfirmationBeforeRunAnAgent
54
59
},
55
60
props: {
56
61
color: String
@@ -65,25 +70,20 @@ export default {
65
70
selectedAgentId: ' -1'
66
71
}
67
72
},
73
+ mixins: [StatusMessageMixin],
68
74
computed: {
69
75
... mapGetters (' agent' , [' getLastAgentRootDomain' , ' getAgentsByType' ]),
70
76
... mapGetters (' target' , [' listRootDomainsAgents' , ' listCurrentRunningRootDomainsAgent' ]),
71
77
... mapState (' target' , [' agentStatus' ]),
72
- ... mapState (' agent' , [' agentListStore' ]),
73
- listAgents : function () {
74
- return this .listRootDomainsAgents ({
75
- idTarget: this .$route .params .idTarget ,
76
- idRoot: this .$route .params .id
77
- })
78
- },
78
+ ... mapState (' agent' , [' agentListStore' , ' rootDomainAgents' ]),
79
79
isRunningAgent : function () {
80
- return this .listCurrentRunningRootDomainsAgent ({ idTarget: this .$route .params .idTarget , idRoot: this .$route .params .id , idAgent: this .selectedAgentId })
80
+ return this .listCurrentRunningRootDomainsAgent ({ idTarget: this .$route .params .targetName , idRoot: this .$route .params .rootdomainName , idAgent: this .selectedAgentId })
81
81
},
82
82
agentsList : function () {
83
83
const rootDomainAgentsType = JSON .parse (JSON .stringify (this .getAgentsByType (this .$agentType .ROOTDOMAIN )))
84
84
const rootDoaminsAgentsCurentView = this .listRootDomainsAgents ({
85
- idTarget : this .$route .params .idTarget ,
86
- idRoot : this .$route .params .id
85
+ targetName : this .$route .params .targetName ,
86
+ rootDomainName : this .$route .params .rootdomainName
87
87
})
88
88
let searchedAgent = null
89
89
rootDomainAgentsType .forEach (element => {
@@ -96,6 +96,10 @@ export default {
96
96
}
97
97
},
98
98
methods: {
99
+ ... mapMutations (' target' , [' setAgentStatus' , ' insertAgentIfNotExistInRootDomain' ]),
100
+ ... mapMutations (' agent' , [' updateStatusRootDomainAgent' ]),
101
+ ... mapMutations (' notification' , [' addNewNotification' ]),
102
+ ... mapActions (' agent' , [' runAgentToServer' ]),
99
103
orderByName : function () {
100
104
if (this .active_arrow_down === true ) {
101
105
return this .orderByNameDesc ()
@@ -104,20 +108,18 @@ export default {
104
108
}
105
109
},
106
110
selectAgent (e ) {
107
- this .selectedAgentName = e .currentTarget .getAttribute (' data-name' )
108
- this .selectedAgentId = e .currentTarget .getAttribute (' data-id' )
111
+ this .selectedAgentName = ' '
112
+ this .selectedAgentId = ' '
113
+ if (e .currentTarget ) {
114
+ this .selectedAgentName = e .currentTarget .getAttribute (' data-name' )
115
+ this .selectedAgentId = e .currentTarget .getAttribute (' data-id' )
116
+ } else {
117
+ this .selectedAgentName = e .dataName
118
+ this .selectedAgentId = e .dataId
119
+ }
109
120
this .addNewNotification (' Running agent' + ' ' + this .selectedAgentName )
110
- this .insertAgentIfNotExistInRootDomain (
111
- {
112
- idTarget: this .$route .params .idTarget ,
113
- idRoot: this .$route .params .id ,
114
- agentData: this .agentListStore .find (item => item .id === this .selectedAgentId )
115
- }
116
- )
117
121
this .updateStatusRootDomainAgent ({
118
122
status: this .$entityStatus .RUNNING ,
119
- idTarget: this .$route .params .idTarget ,
120
- idRoot: this .$route .params .id ,
121
123
idAgent: this .selectedAgentId
122
124
})
123
125
this .setAgentStatus ({ status: this .$entityStatus .RUNNING , id: this .selectedAgentId })
@@ -156,8 +158,25 @@ export default {
156
158
)
157
159
}
158
160
},
159
- ... mapMutations (' target' , [' setAgentStatus' , ' updateStatusRootDomainAgent' , ' insertAgentIfNotExistInRootDomain' ]),
160
- ... mapMutations (' notification' , [' addNewNotification' ])
161
+ runAgent (e ) {
162
+ jQuery (' #agentExecutionModalForm' ).modal (' show' )
163
+ this .runAgentToServer (
164
+ {
165
+ agent: e .dataName ,
166
+ target: this .$route .params .targetName ,
167
+ rootdomain: this .$route .params .rootdomainName ,
168
+ command: e .command ,
169
+ activateNotification: e .activateNotification
170
+ }
171
+ ).then (response => {
172
+ if (response .status ) {
173
+ this .selectAgent (e)
174
+ this .updateOperationStatus (this .$entityStatus .SUCCESS , ' ' )
175
+ } else {
176
+ this .updateOperationStatus (this .$entityStatus .FAILED , response .message )
177
+ }
178
+ })
179
+ }
161
180
}
162
181
}
163
182
</script >
0 commit comments