[go: nahoru, domu]

Skip to content

Commit

Permalink
ui: refactoring $notification according to the old version (apache#5819)
Browse files Browse the repository at this point in the history
Related to PR apache#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.
  • Loading branch information
Hoang Nguyen authored Jan 3, 2022
1 parent 5f93bc8 commit 4392cc4
Show file tree
Hide file tree
Showing 73 changed files with 198 additions and 295 deletions.
3 changes: 1 addition & 2 deletions ui/src/components/view/DetailSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,7 @@ export default {
apiName = 'updateTemplate'
}
if (!(apiName in this.$store.getters.apis)) {
this.$showNotification({
type: 'error',
this.$notification.error({
message: this.$t('error.execute.api.failed') + ' ' + apiName,
description: this.$t('message.user.not.permitted.api')
})
Expand Down
3 changes: 1 addition & 2 deletions ui/src/components/view/ListView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -514,8 +514,7 @@ export default {
json.updateconfigurationresponse.configuration &&
!json.updateconfigurationresponse.configuration.isdynamic &&
['Admin'].includes(this.$store.getters.userInfo.roletype)) {
this.$showNotification({
type: 'warning',
this.$notification.warning({
message: this.$t('label.status'),
description: this.$t('message.restart.mgmt.server')
})
Expand Down
3 changes: 1 addition & 2 deletions ui/src/components/view/ResourceLimitTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ export default {
this.dataResource = await this.listResourceLimits(params)
this.formLoading = false
} catch (e) {
this.$showNotification({
type: 'error',
this.$notification.error({
message: this.$t('message.request.failed'),
description: e
})
Expand Down
3 changes: 1 addition & 2 deletions ui/src/components/view/SettingsTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,7 @@ export default {
}).catch(error => {
console.error(error)
this.$message.error(this.$t('message.error.save.setting'))
this.$showNotification({
type: 'error',
this.$notification.error({
message: this.$t('label.error'),
description: this.$t('message.error.try.save.setting')
})
Expand Down
12 changes: 4 additions & 8 deletions ui/src/components/view/UploadResourceIcon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,13 @@ export default {
}).then(json => {
console.log(this.resource)
if (json?.uploadresourceiconresponse?.success) {
this.$showNotification({
type: 'success',
this.$notification.success({
message: this.$t('label.upload.icon'),
description: `${this.$t('message.success.upload.icon')} ${resourceType}: ` + (this.resource.name || this.resource.username || resourceid)
})
}
}).catch((error) => {
this.$showNotification({
type: 'error',
this.$notification.error({
message: this.$t('label.upload.icon'),
description: error?.response?.data?.uploadresourceiconresponse?.errortext || '',
duration: 0
Expand All @@ -266,15 +264,13 @@ export default {
resourceids: resourceid
}).then(json => {
if (json?.deleteresourceiconresponse?.success) {
this.$showNotification({
type: 'success',
this.$notification.success({
message: this.$t('label.delete.icon'),
description: `${this.$t('message.success.delete.icon')} ${resourceType}: ` + (this.resource.name || this.resource.username || resourceid)
})
}
}).catch((error) => {
this.$showNotification({
type: 'error',
this.$notification.error({
message: this.$t('label.delete.icon'),
description: error?.response?.data?.deleteresourceiconresponse?.errortext || '',
duration: 0
Expand Down
6 changes: 2 additions & 4 deletions ui/src/config/section/compute.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ export default {
const vm = result.jobresult.virtualmachine || {}
if (result.jobstatus === 1 && vm.password) {
const name = vm.displayname || vm.name || vm.id
obj.$showNotification({
type: 'success',
obj.$notification.success({
message: `${obj.$t('label.reinstall.vm')}: ` + name,
description: `${obj.$t('label.password.reset.confirm')}: ` + vm.password,
duration: 0
Expand Down Expand Up @@ -362,8 +361,7 @@ export default {
const vm = result.jobresult.virtualmachine || {}
if (result.jobstatus === 1 && vm.password) {
const name = vm.displayname || vm.name || vm.id
obj.$showNotification({
type: 'success',
obj.$notification.success({
message: `${obj.$t('label.reset.ssh.key.pair.on.vm')}: ` + name,
description: `${obj.$t('label.password.reset.confirm')}: ` + vm.password,
duration: 0
Expand Down
1 change: 0 additions & 1 deletion ui/src/core/lazy_lib/components_use.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ Vue.use(VueCropper)

Vue.prototype.$confirm = Modal.confirm
Vue.prototype.$message = message
Vue.prototype.$notification = notification
Vue.prototype.$info = Modal.info
Vue.prototype.$success = Modal.success
Vue.prototype.$error = Modal.error
Expand Down
56 changes: 35 additions & 21 deletions ui/src/utils/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,33 +237,47 @@ export const notifierPlugin = {
})
}

Vue.prototype.$showNotification = function (config) {
let countNotify = store.getters.countNotify
countNotify++
store.commit('SET_COUNT_NOTIFY', countNotify)
const defaultConfig = {
Vue.prototype.$notification = {
defaultConfig: {
top: '65px',
onClose: () => {
let countNotify = store.getters.countNotify
countNotify > 0 ? countNotify-- : countNotify = 0
store.commit('SET_COUNT_NOTIFY', countNotify)
}
}
config = Object.assign({}, defaultConfig, config)
switch (config.type) {
case 'info':
notification.info(config)
break
case 'error':
notification.error(config)
break
case 'success':
notification.success(config)
break
case 'warning':
notification.warning(config)
break
}
},
setCountNotify: () => {
let countNotify = store.getters.countNotify
countNotify++
store.commit('SET_COUNT_NOTIFY', countNotify)
},
info: (config) => {
Vue.prototype.$notification.setCountNotify()
config = Object.assign({}, Vue.prototype.$notification.defaultConfig, config)
notification.info(config)
},
error: (config) => {
Vue.prototype.$notification.setCountNotify()
config = Object.assign({}, Vue.prototype.$notification.defaultConfig, config)
notification.error(config)
},
success: (config) => {
Vue.prototype.$notification.setCountNotify()
config = Object.assign({}, Vue.prototype.$notification.defaultConfig, config)
notification.success(config)
},
warning: (config) => {
Vue.prototype.$notification.setCountNotify()
config = Object.assign({}, Vue.prototype.$notification.defaultConfig, config)
notification.warning(config)
},
warn: (config) => {
Vue.prototype.$notification.setCountNotify()
config = Object.assign({}, Vue.prototype.$notification.defaultConfig, config)
notification.warn(config)
},
close: (key) => notification.close(key),
destroy: () => notification.destroy()
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions ui/src/views/AutogenView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1128,8 +1128,7 @@ export default {
if (action.response) {
const description = action.response(result.jobresult)
if (description) {
this.$showNotification({
type: 'info',
this.$notification.info({
message: this.$t(action.label),
description: (<span domPropsInnerHTML={description}></span>),
duration: 0
Expand Down
3 changes: 1 addition & 2 deletions ui/src/views/compute/AssignInstance.vue
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,7 @@ export default {
[variableKey]: variableValue,
networkids: this.selectedNetwork
}).then(response => {
this.$showNotification({
type: 'success',
this.$notification.success({
message: this.$t('label.loadbalancerinstance')
})
this.$parent.$parent.close()
Expand Down
3 changes: 1 addition & 2 deletions ui/src/views/compute/ChangeAffinity.vue
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,7 @@ export default {
id: this.resource.id,
affinitygroupids: this.selectedRowKeys.join(',')
}).then(response => {
this.$showNotification({
type: 'success',
this.$notification.success({
message: this.$t('message.success.change.affinity.group')
})
this.$parent.$parent.close()
Expand Down
3 changes: 1 addition & 2 deletions ui/src/views/compute/CreateSSHKeyPair.vue
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,7 @@ export default {
this.hiddenElement.click()
},
notifyCopied () {
this.$showNotification({
type: 'info',
this.$notification.info({
message: this.$t('message.success.copy.clipboard')
})
},
Expand Down
3 changes: 1 addition & 2 deletions ui/src/views/compute/CreateSnapshotWizard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,7 @@ export default {
const volumeId = result.jobresult.snapshot.volumeid
const snapshotId = result.jobresult.snapshot.id
const message = `${this.$t('label.create.snapshot.for.volume')} ${volumeId} ${this.$t('label.with.snapshotid')} ${snapshotId}`
this.$showNotification({
type: 'success',
this.$notification.success({
message: message,
duration: 0
})
Expand Down
23 changes: 8 additions & 15 deletions ui/src/views/compute/DeployVM.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1491,48 +1491,43 @@ export default {
this.form.validateFieldsAndScroll(options, async (err, values) => {
if (err) {
if (err.licensesaccepted) {
this.$showNotification({
this.$notification.error({
type: 'error',
message: this.$t('message.license.agreements.not.accepted'),
description: this.$t('message.step.license.agreements.continue')
})
return
}
this.$showNotification({
type: 'error',
this.$notification.error({
message: this.$t('message.request.failed'),
description: this.$t('error.form.message')
})
return
}
if (!values.templateid && !values.isoid) {
this.$showNotification({
type: 'error',
this.$notification.error({
message: this.$t('message.request.failed'),
description: this.$t('message.template.iso')
})
return
} else if (values.isoid && (!values.diskofferingid || values.diskofferingid === '0')) {
this.$showNotification({
type: 'error',
this.$notification.error({
message: this.$t('message.request.failed'),
description: this.$t('message.step.3.continue')
})
return
}
if (!values.computeofferingid) {
this.$showNotification({
type: 'error',
this.$notification.error({
message: this.$t('message.request.failed'),
description: this.$t('message.step.2.continue')
})
return
}
if (this.error) {
this.$showNotification({
type: 'error',
this.$notification.error({
message: this.$t('message.request.failed'),
description: this.$t('error.form.message')
})
Expand Down Expand Up @@ -1645,8 +1640,7 @@ export default {
}
}
} else {
this.$showNotification({
type: 'error',
this.$notification.error({
message: this.$t('message.request.failed'),
description: this.$t('message.step.4.continue')
})
Expand Down Expand Up @@ -1708,8 +1702,7 @@ export default {
const vm = result.jobresult.virtualmachine
const name = vm.displayname || vm.name || vm.id
if (vm.password) {
this.$showNotification({
type: 'success',
this.$notification.error({
message: password + ` ${this.$t('label.for')} ` + name,
description: vm.password,
duration: 0
Expand Down
3 changes: 1 addition & 2 deletions ui/src/views/compute/KubernetesServiceTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,7 @@ export default {
config.configdata !== '') {
this.clusterConfig = config.configdata
} else {
this.$showNotification({
type: 'error',
this.$notification.error({
message: this.$t('message.request.failed'),
description: this.$t('message.error.retrieve.kubeconfig')
})
Expand Down
3 changes: 1 addition & 2 deletions ui/src/views/compute/MigrateWizard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,7 @@ export default {
})
this.$emit('close-action')
}).catch(error => {
this.$showNotification({
type: 'error',
this.$notification.error({
message: this.$t('message.request.failed'),
description: (error.response && error.response.headers && error.response.headers['x-description']) || error.message,
duration: 0
Expand Down
3 changes: 1 addition & 2 deletions ui/src/views/compute/ScaleVM.vue
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,7 @@ export default {
this.$pollJob({
jobId,
successMethod: result => {
this.$showNotification({
type: 'success',
this.$notification.success({
message: this.$t('message.success.change.offering')
})
},
Expand Down
9 changes: 3 additions & 6 deletions ui/src/views/compute/StartVirtualMachine.vue
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@ export default {
api('listPods', params).then(json => {
this.pods = json.listpodsresponse.pod || []
if (this.pods.length === 0) {
this.$showNotification({
type: 'error',
this.$notification.error({
message: 'No pods found',
duration: 0
})
Expand All @@ -163,8 +162,7 @@ export default {
api('listClusters', params).then(json => {
this.clusters = json.listclustersresponse.cluster || []
if (this.clusters.length === 0) {
this.$showNotification({
type: 'error',
this.$notification.error({
message: 'No clusters found',
duration: 0
})
Expand All @@ -186,8 +184,7 @@ export default {
api('listHosts', params).then(json => {
this.hosts = json.listhostsresponse.host || []
if (this.hosts.length === 0) {
this.$showNotification({
type: 'error',
this.$notification.error({
message: 'No hosts found',
duration: 0
})
Expand Down
3 changes: 1 addition & 2 deletions ui/src/views/compute/backup/BackupSchedule.vue
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@ export default {
this.actionLoading = true
api('deleteBackupSchedule', params).then(json => {
if (json.deletebackupscheduleresponse.success) {
this.$showNotification({
type: 'success',
this.$notification.success({
message: this.$t('label.scheduled.backups'),
description: this.$t('message.success.delete.backup.schedule')
})
Expand Down
3 changes: 1 addition & 2 deletions ui/src/views/compute/backup/FormSchedule.vue
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,7 @@ export default {
}
this.actionLoading = true
api('createBackupSchedule', params).then(json => {
this.$showNotification({
type: 'success',
this.$notification.success({
message: this.$t('label.scheduled.backups'),
description: this.$t('message.success.config.backup.schedule')
})
Expand Down
Loading

0 comments on commit 4392cc4

Please sign in to comment.