Skip to content

Commit

Permalink
pop up notify box when component is added/removed.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jing Teng authored and tecimovic committed Dec 9, 2020
1 parent 54744e0 commit 4c33d11
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 15 deletions.
3 changes: 2 additions & 1 deletion quasar.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ module.exports = function (ctx) {
directives: [],

// Quasar plugins
plugins: ['Loading'],
plugins: ['Loading', 'Notify'],
config: {
loading: {},
notify: {},
},
},

Expand Down
18 changes: 4 additions & 14 deletions src/components/UcComponentSetup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ limitations under the License.

<script>
const restApi = require('../../src-shared/rest-api.js')
import CommonMixin from '../util/common-mixin'

export default {
name: 'UcComponentSetup',
mixins: [CommonMixin],

data() {
return {
Expand Down Expand Up @@ -90,26 +92,14 @@ export default {
(x) => !this.uc.ticked.includes(x)
)

console.log('Enable: ' + enabledItems)
enabledItems.forEach(function (item) {
let id = item.substr(item.lastIndexOf('-') + 1)
this.$serverGet(restApi.uc.componentAdd, {
params: {
componentId: id,
studioProject: this.$store.state.zap.studioProject,
},
})
this.updateComponent(id, this.$store.state.zap.studioProject, true)
}, this)

console.log('Disable: ' + disabledItems)
disabledItems.forEach(function (item) {
let id = item.substr(item.lastIndexOf('-') + 1)
this.$serverGet(restApi.uc.componentRemove, {
params: {
componentId: id,
studioProject: this.$store.state.zap.studioProject,
},
})
this.updateComponent(id, this.$store.state.zap.studioProject, false)
}, this)

this.uc.last_ticked = this.uc.ticked
Expand Down
48 changes: 48 additions & 0 deletions src/util/common-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

import * as Util from './util'
import * as RestApi from '../../src-shared/rest-api'

/**
* This module provides common computed properties used across various vue components
Expand Down Expand Up @@ -110,5 +111,52 @@ export default {
})
this.$store.dispatch('zap/updateSelectedEndpoint', endpointReference)
},
updateComponent(componentId, studioProject, addComponent) {
let op = RestApi.uc.componentAdd
if (addComponent) {
op = RestApi.uc.componentAdd
} else {
op = RestApi.uc.componentRemove
}

this.$serverGet(op, {
params: {
componentId: componentId,
studioProject: this.$store.state.zap.studioProject,
},
})
.then((res) => {
let msg = ''
let name = componentId.replace(/_/g, ' ')
if (op == RestApi.uc.componentAdd) {
msg +=
'<div><strong>Component was successfully added.</strong></div>'
msg += `<div>The <span style="text-transform: capitalize">${name}</span> was added.</div>`
} else {
msg +=
'<div><strong>Component was successfully removed.</strong></div>'
msg += `<div>The <span style="text-transform: capitalize">${name}</span> was removed.</div>`
}

console.log(msg)
this.$q.notify({
message: msg,
color: 'positive',
position: 'top',
html: true,
})
})
.catch((err) => {
this.$q.notify({
message:
'Unable to ' +
(op == RestApi.uc.componentAdd ? 'add' : 'remove') +
' ' +
componentId,
color: 'negative',
position: 'top',
})
})
},
},
}

0 comments on commit 4c33d11

Please sign in to comment.