Skip to content

Commit 4392cc4

Browse files
author
Hoang Nguyen
authored
ui: refactoring $notification according to the old version (#5819)
Related to PR #5549 changed the notification from $notification to $showNotification. This PR aims to change it back to the way it was for easier use while keeping the delete all button.
1 parent 5f93bc8 commit 4392cc4

File tree

73 files changed

+198
-295
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+198
-295
lines changed

ui/src/components/view/DetailSettings.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,7 @@ export default {
219219
apiName = 'updateTemplate'
220220
}
221221
if (!(apiName in this.$store.getters.apis)) {
222-
this.$showNotification({
223-
type: 'error',
222+
this.$notification.error({
224223
message: this.$t('error.execute.api.failed') + ' ' + apiName,
225224
description: this.$t('message.user.not.permitted.api')
226225
})

ui/src/components/view/ListView.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,8 +514,7 @@ export default {
514514
json.updateconfigurationresponse.configuration &&
515515
!json.updateconfigurationresponse.configuration.isdynamic &&
516516
['Admin'].includes(this.$store.getters.userInfo.roletype)) {
517-
this.$showNotification({
518-
type: 'warning',
517+
this.$notification.warning({
519518
message: this.$t('label.status'),
520519
description: this.$t('message.restart.mgmt.server')
521520
})

ui/src/components/view/ResourceLimitTab.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,7 @@ export default {
107107
this.dataResource = await this.listResourceLimits(params)
108108
this.formLoading = false
109109
} catch (e) {
110-
this.$showNotification({
111-
type: 'error',
110+
this.$notification.error({
112111
message: this.$t('message.request.failed'),
113112
description: e
114113
})

ui/src/components/view/SettingsTab.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,7 @@ export default {
164164
}).catch(error => {
165165
console.error(error)
166166
this.$message.error(this.$t('message.error.save.setting'))
167-
this.$showNotification({
168-
type: 'error',
167+
this.$notification.error({
169168
message: this.$t('label.error'),
170169
description: this.$t('message.error.try.save.setting')
171170
})

ui/src/components/view/UploadResourceIcon.vue

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -234,15 +234,13 @@ export default {
234234
}).then(json => {
235235
console.log(this.resource)
236236
if (json?.uploadresourceiconresponse?.success) {
237-
this.$showNotification({
238-
type: 'success',
237+
this.$notification.success({
239238
message: this.$t('label.upload.icon'),
240239
description: `${this.$t('message.success.upload.icon')} ${resourceType}: ` + (this.resource.name || this.resource.username || resourceid)
241240
})
242241
}
243242
}).catch((error) => {
244-
this.$showNotification({
245-
type: 'error',
243+
this.$notification.error({
246244
message: this.$t('label.upload.icon'),
247245
description: error?.response?.data?.uploadresourceiconresponse?.errortext || '',
248246
duration: 0
@@ -266,15 +264,13 @@ export default {
266264
resourceids: resourceid
267265
}).then(json => {
268266
if (json?.deleteresourceiconresponse?.success) {
269-
this.$showNotification({
270-
type: 'success',
267+
this.$notification.success({
271268
message: this.$t('label.delete.icon'),
272269
description: `${this.$t('message.success.delete.icon')} ${resourceType}: ` + (this.resource.name || this.resource.username || resourceid)
273270
})
274271
}
275272
}).catch((error) => {
276-
this.$showNotification({
277-
type: 'error',
273+
this.$notification.error({
278274
message: this.$t('label.delete.icon'),
279275
description: error?.response?.data?.deleteresourceiconresponse?.errortext || '',
280276
duration: 0

ui/src/config/section/compute.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,7 @@ export default {
152152
const vm = result.jobresult.virtualmachine || {}
153153
if (result.jobstatus === 1 && vm.password) {
154154
const name = vm.displayname || vm.name || vm.id
155-
obj.$showNotification({
156-
type: 'success',
155+
obj.$notification.success({
157156
message: `${obj.$t('label.reinstall.vm')}: ` + name,
158157
description: `${obj.$t('label.password.reset.confirm')}: ` + vm.password,
159158
duration: 0
@@ -362,8 +361,7 @@ export default {
362361
const vm = result.jobresult.virtualmachine || {}
363362
if (result.jobstatus === 1 && vm.password) {
364363
const name = vm.displayname || vm.name || vm.id
365-
obj.$showNotification({
366-
type: 'success',
364+
obj.$notification.success({
367365
message: `${obj.$t('label.reset.ssh.key.pair.on.vm')}: ` + name,
368366
description: `${obj.$t('label.password.reset.confirm')}: ` + vm.password,
369367
duration: 0

ui/src/core/lazy_lib/components_use.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ Vue.use(VueCropper)
122122

123123
Vue.prototype.$confirm = Modal.confirm
124124
Vue.prototype.$message = message
125-
Vue.prototype.$notification = notification
126125
Vue.prototype.$info = Modal.info
127126
Vue.prototype.$success = Modal.success
128127
Vue.prototype.$error = Modal.error

ui/src/utils/plugins.js

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -237,33 +237,47 @@ export const notifierPlugin = {
237237
})
238238
}
239239

240-
Vue.prototype.$showNotification = function (config) {
241-
let countNotify = store.getters.countNotify
242-
countNotify++
243-
store.commit('SET_COUNT_NOTIFY', countNotify)
244-
const defaultConfig = {
240+
Vue.prototype.$notification = {
241+
defaultConfig: {
245242
top: '65px',
246243
onClose: () => {
247244
let countNotify = store.getters.countNotify
248245
countNotify > 0 ? countNotify-- : countNotify = 0
249246
store.commit('SET_COUNT_NOTIFY', countNotify)
250247
}
251-
}
252-
config = Object.assign({}, defaultConfig, config)
253-
switch (config.type) {
254-
case 'info':
255-
notification.info(config)
256-
break
257-
case 'error':
258-
notification.error(config)
259-
break
260-
case 'success':
261-
notification.success(config)
262-
break
263-
case 'warning':
264-
notification.warning(config)
265-
break
266-
}
248+
},
249+
setCountNotify: () => {
250+
let countNotify = store.getters.countNotify
251+
countNotify++
252+
store.commit('SET_COUNT_NOTIFY', countNotify)
253+
},
254+
info: (config) => {
255+
Vue.prototype.$notification.setCountNotify()
256+
config = Object.assign({}, Vue.prototype.$notification.defaultConfig, config)
257+
notification.info(config)
258+
},
259+
error: (config) => {
260+
Vue.prototype.$notification.setCountNotify()
261+
config = Object.assign({}, Vue.prototype.$notification.defaultConfig, config)
262+
notification.error(config)
263+
},
264+
success: (config) => {
265+
Vue.prototype.$notification.setCountNotify()
266+
config = Object.assign({}, Vue.prototype.$notification.defaultConfig, config)
267+
notification.success(config)
268+
},
269+
warning: (config) => {
270+
Vue.prototype.$notification.setCountNotify()
271+
config = Object.assign({}, Vue.prototype.$notification.defaultConfig, config)
272+
notification.warning(config)
273+
},
274+
warn: (config) => {
275+
Vue.prototype.$notification.setCountNotify()
276+
config = Object.assign({}, Vue.prototype.$notification.defaultConfig, config)
277+
notification.warn(config)
278+
},
279+
close: (key) => notification.close(key),
280+
destroy: () => notification.destroy()
267281
}
268282
}
269283
}

ui/src/views/AutogenView.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,8 +1128,7 @@ export default {
11281128
if (action.response) {
11291129
const description = action.response(result.jobresult)
11301130
if (description) {
1131-
this.$showNotification({
1132-
type: 'info',
1131+
this.$notification.info({
11331132
message: this.$t(action.label),
11341133
description: (<span domPropsInnerHTML={description}></span>),
11351134
duration: 0

ui/src/views/compute/AssignInstance.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,7 @@ export default {
294294
[variableKey]: variableValue,
295295
networkids: this.selectedNetwork
296296
}).then(response => {
297-
this.$showNotification({
298-
type: 'success',
297+
this.$notification.success({
299298
message: this.$t('label.loadbalancerinstance')
300299
})
301300
this.$parent.$parent.close()

0 commit comments

Comments
 (0)