3232 <a-button size =" small" slot =" description" @click =" clearJobs" >{{ $t('label.clear.list') }}</a-button >
3333 </a-list-item-meta >
3434 </a-list-item >
35- <a-list-item v-for =" (job , index) in jobs " :key =" index" >
36- <a-list-item-meta :title =" job .title" >
37- <a-avatar :style =" notificationAvatar[job .status].style" :icon =" notificationAvatar[job .status].icon" slot =" avatar" />< br />
38- <span v-if =" getResourceName(job .description, 'name') && job .path" slot =" description" ><router-link :to =" { path: job .path}" > {{ getResourceName(job .description, "name") + ' - ' }}</router-link ></span >
39- <span v-if =" getResourceName(job .description, 'name') && job .path" slot =" description" > {{ getResourceName(job .description, "msg") }}</span >
40- <span v-else slot =" description" > {{ job .description }} </span >
35+ <a-list-item v-for =" (notice , index) in notices " :key =" index" >
36+ <a-list-item-meta :title =" notice .title" :description = " notice.description " >
37+ <a-avatar :style =" notificationAvatar[notice .status].style" :icon =" notificationAvatar[notice .status].icon" slot =" avatar" />
38+ <span v-if =" getResourceName(notice .description, 'name') && notice .path" slot =" description" ><router-link :to =" { path: notice .path}" > {{ getResourceName(notice .description, "name") + ' - ' }}</router-link ></span >
39+ <span v-if =" getResourceName(notice .description, 'name') && notice .path" slot =" description" > {{ getResourceName(notice .description, "msg") }}</span >
40+ <span v-else slot =" description" > {{ notice .description }} </span >
4141 </a-list-item-meta >
4242 </a-list-item >
4343 </a-list >
4444 </a-spin >
4545 </template >
4646 <span @click =" showNotifications" class =" header-notice-opener" >
47- <a-badge :count =" jobs .length" >
47+ <a-badge :count =" notices .length" >
4848 <a-icon class =" header-notice-icon" type =" bell" />
4949 </a-badge >
5050 </span >
5151 </a-popover >
5252</template >
5353
5454<script >
55- import { api } from ' @/api'
5655import store from ' @/store'
5756
5857export default {
@@ -61,7 +60,7 @@ export default {
6160 return {
6261 loading: false ,
6362 visible: false ,
64- jobs : [],
63+ notices : [],
6564 poller: null ,
6665 notificationAvatar: {
6766 done: { icon: ' check-circle' , style: ' backgroundColor:#87d068' },
@@ -75,13 +74,8 @@ export default {
7574 this .visible = ! this .visible
7675 },
7776 clearJobs () {
78- this .jobs = this .jobs .filter (x => x .status === ' progress' )
79- this .$store .commit (' SET_ASYNC_JOB_IDS' , this .jobs )
80- },
81- startPolling () {
82- this .poller = setInterval (() => {
83- this .pollJobs ()
84- }, 4000 )
77+ this .notices = this .notices .filter (x => x .status === ' progress' )
78+ this .$store .commit (' SET_HEADER_NOTICES' , this .notices )
8579 },
8680 getResourceName (description , data ) {
8781 if (description) {
@@ -92,61 +86,15 @@ export default {
9286 const msg = description .substring (description .indexOf (' )' ) + 1 )
9387 return msg
9488 }
95- },
96- async pollJobs () {
97- var hasUpdated = false
98- for (var i in this .jobs ) {
99- if (this .jobs [i].status === ' progress' ) {
100- await api (' queryAsyncJobResult' , { jobid: this .jobs [i].jobid }).then (json => {
101- var result = json .queryasyncjobresultresponse
102- if (result .jobstatus === 1 && this .jobs [i].status !== ' done' ) {
103- hasUpdated = true
104- const title = this .jobs [i].title
105- const description = this .jobs [i].description
106- this .$message .success ({
107- content: title + (description ? ' - ' + description : ' ' ),
108- key: this .jobs [i].jobid ,
109- duration: 2
110- })
111- this .jobs [i].status = ' done'
112- } else if (result .jobstatus === 2 && this .jobs [i].status !== ' failed' ) {
113- hasUpdated = true
114- this .jobs [i].status = ' failed'
115- if (result .jobresult .errortext !== null ) {
116- this .jobs [i].description = ' (' + this .jobs [i].description + ' ) ' + result .jobresult .errortext
117- }
118- if (! this .jobs [i].bulkAction ) {
119- this .$notification .error ({
120- message: this .jobs [i].title ,
121- description: this .jobs [i].description ,
122- key: this .jobs [i].jobid ,
123- duration: 0
124- })
125- }
126- }
127- }).catch (function (e ) {
128- console .log (this .$t (' error.fetching.async.job.result' ) + e)
129- })
130- }
131- }
132- if (hasUpdated) {
133- this .$store .commit (' SET_ASYNC_JOB_IDS' , this .jobs .reverse ())
134- }
13589 }
13690 },
137- beforeDestroy () {
138- clearInterval (this .poller )
139- },
140- created () {
141- this .startPolling ()
142- },
14391 mounted () {
144- this .jobs = (store .getters .asyncJobIds || []).reverse ()
92+ this .notices = (store .getters .headerNotices || []).reverse ()
14593 this .$store .watch (
146- (state , getters ) => getters .asyncJobIds ,
94+ (state , getters ) => getters .headerNotices ,
14795 (newValue , oldValue ) => {
14896 if (oldValue !== newValue && newValue !== undefined ) {
149- this .jobs = newValue .reverse ()
97+ this .notices = newValue .reverse ()
15098 }
15199 }
152100 )
0 commit comments