TT#39589 CallBlocking: Refactor component, actions and store methods

Change-Id: Iac9b421c0684b1ecc2db0b4482c229ff5b5634ea
changes/95/22395/4
Hans-Peter Herzog 7 years ago
parent 54c1b07b61
commit 84d019734b

@ -1,13 +1,20 @@
import _ from 'lodash'; import _ from 'lodash';
import { enableBlockIn, disableBlockIn, import {
getPreferences, addToBlockInList, enableBlockIn,
editBlockInList, removeFromBlockInList, disableBlockIn,
enableBlockOut, disableBlockOut, getPreferences,
addToBlockOutList, editBlockOutList, addToBlockInList,
editBlockInList,
removeFromBlockInList,
enableBlockOut,
disableBlockOut,
addToBlockOutList,
editBlockOutList,
removeFromBlockOutList, removeFromBlockOutList,
enablePrivacy, disablePrivacy enablePrivacy,
disablePrivacy
} from './subscriber'; } from './subscriber';
export function enableIncomingCallBlocking(id) { export function enableIncomingCallBlocking(id) {
@ -133,9 +140,7 @@ export function disablePrivacyCallBlocking(id) {
export function getPrivacyCallBlocking(id) { export function getPrivacyCallBlocking(id) {
return new Promise((resolve, reject)=>{ return new Promise((resolve, reject)=>{
getPreferences(id).then((result)=>{ getPreferences(id).then((result)=>{
resolve({ resolve(result.clir);
enabled: result.clir
});
}).catch((err)=>{ }).catch((err)=>{
reject(err); reject(err);
}); });

@ -1,45 +1,106 @@
<template> <template>
<csc-page title="Privacy" class="csc-simple-page"> <csc-page
<q-toggle :label="(!callBlockingEnabled ? 'Hide' : 'Show') + ' Own Number'" class="csc-simple-page"
@input="toggle()" v-model="callBlockingEnabled"/> >
<q-field
class="csc-privacy"
>
<q-toggle
:label="privacyLabel"
:value="privacy"
@input="toggle()"
checked-icon="visibility_off"
unchecked-icon="visibility"
/>
<q-inner-loading
v-if="privacyLoading"
:visible="privacyLoading"
>
<q-spinner-mat
size="30px"
color="primary"
/>
</q-inner-loading>
</q-field>
</csc-page> </csc-page>
</template> </template>
<script> <script>
import { showToast } from '../../../helpers/ui'
import {
mapGetters
} from 'vuex'
import {
showToast
} from '../../../helpers/ui'
import CscPage from '../../CscPage' import CscPage from '../../CscPage'
import { QField, QToggle, Toast } from 'quasar-framework' import {
QField,
QToggle,
Toast,
QInnerLoading,
QSpinnerMat
} from 'quasar-framework'
export default { export default {
data () { data () {
return { return {}
callBlockingEnabled: false
}
},
mounted() {
this.$store.dispatch('callBlocking/loadPrivacy').then(()=>{
this.callBlockingEnabled = this.$store.state.callBlocking.privacyEnabled;
}).catch((err)=>{
console.log(err);
});
}, },
components: { components: {
CscPage, CscPage,
QToggle, QToggle,
Toast, Toast,
QField QField,
QInnerLoading,
QSpinnerMat
},
mounted() {
this.$store.dispatch('callBlocking/loadPrivacy');
},
computed: {
privacyLabel() {
if(this.privacy) {
return this.$t('callBlocking.privacyEnabledLabel');
}
else {
return this.$t('callBlocking.privacyDisabledLabel');
}
},
fieldIcon() {
if(!this.privacy) {
return 'visibility';
}
else {
return 'visibility_off';
}
},
...mapGetters('callBlocking', [
'privacy',
'privacyError',
'privacyUpdated',
'privacyLoadingState',
'privacyLoading'
])
}, },
methods: { methods: {
toggle () { toggle () {
this.$store.dispatch('callBlocking/togglePrivacy', this.callBlockingEnabled).then(()=>{ this.$store.dispatch('callBlocking/updatePrivacy', !this.privacy);
showToast('Own number will now be ' + (this.callBlockingEnabled ? 'hidden' : 'shown') + }
' on outbound calls'); },
}).catch((err)=>{ watch: {
console.log(err); privacyUpdated(updated) {
}); if(updated && this.privacy) {
showToast(this.$t('callBlocking.privacyEnabledToast'));
}
else if (updated && !this.privacy) {
showToast(this.$t('callBlocking.privacyDisabledToast'));
}
} }
} }
} }
</script> </script>
<style lang="stylus" rel="stylesheet/stylus"> <style lang="stylus" rel="stylesheet/stylus">
.csc-privacy
position relative
</style> </style>

@ -318,6 +318,12 @@
"keyTypePrivate": "Private", "keyTypePrivate": "Private",
"filterPhoneModel": "Filter by phone model" "filterPhoneModel": "Filter by phone model"
}, },
"callBlocking": {
"privacyEnabledToast": "Your number is hidden to the callee",
"privacyEnabledLabel": "Your number is hidden to the callee",
"privacyDisabledToast": "Your number is visible to the callee",
"privacyDisabledLabel": "Your number is visible to the callee"
},
"communication": { "communication": {
"sendFax": "Send Fax", "sendFax": "Send Fax",
"quality": { "quality": {

@ -1,6 +1,8 @@
'use strict'; 'use strict';
import { enableIncomingCallBlocking, import { RequestState } from './common'
import {
enableIncomingCallBlocking,
disableIncomingCallBlocking, disableIncomingCallBlocking,
getIncomingCallBlocking, getIncomingCallBlocking,
addNumberToIncomingList, addNumberToIncomingList,
@ -12,10 +14,11 @@ import { enableIncomingCallBlocking,
addNumberToOutgoingList, addNumberToOutgoingList,
editNumberFromOutgoingList, editNumberFromOutgoingList,
removeNumberFromOutgoingList, removeNumberFromOutgoingList,
enablePrivacyCallBlocking,
disablePrivacyCallBlocking,
getPrivacyCallBlocking getPrivacyCallBlocking
} from '../api/call-blocking'; } from '../api/call-blocking';
import {
setPrivacy
} from '../api/subscriber';
export default { export default {
namespaced: true, namespaced: true,
@ -24,9 +27,28 @@ export default {
incomingList: [], incomingList: [],
outgoingEnabled: false, outgoingEnabled: false,
outgoingList: [], outgoingList: [],
privacyEnabled: false privacy: false,
privacyLoadingState: RequestState.initiated,
privacyUpdated: false,
privacyError: null
},
getters: {
privacy(state) {
return state.privacy;
},
privacyError(state) {
return state.privacyError;
},
privacyUpdated(state) {
return state.privacyUpdated;
},
privacyLoadingState(state) {
return state.privacyUpdated;
},
privacyLoading(state) {
return state.privacyLoadingState === RequestState.requesting;
}
}, },
getters: {},
mutations: { mutations: {
enableIncoming (state) { enableIncoming (state) {
state.incomingEnabled = true; state.incomingEnabled = true;
@ -38,15 +60,6 @@ export default {
state.incomingEnabled = options.enabled; state.incomingEnabled = options.enabled;
state.incomingList = options.list; state.incomingList = options.list;
}, },
enablePrivacy (state) {
state.privacyEnabled = true;
},
disablePrivacy (state) {
state.privacyEnabled= false;
},
loadPrivacy(state, options) {
state.privacyEnabled = options.enabled;
},
enableOutgoing (state) { enableOutgoing (state) {
state.outgoingEnabled = true; state.outgoingEnabled = true;
}, },
@ -56,6 +69,31 @@ export default {
loadOutgoing(state, options) { loadOutgoing(state, options) {
state.outgoingEnabled = options.enabled; state.outgoingEnabled = options.enabled;
state.outgoingList = options.list; state.outgoingList = options.list;
},
privacyLoading(state) {
state.privacyLoadingState = RequestState.requesting;
state.privacyError = null;
state.privacyUpdated = false;
},
privacyLoaded(state, privacy) {
state.privacy = privacy;
state.privacyLoadingState = RequestState.succeeded;
state.privacyError = null;
},
privacyLoadingFailed(state, error) {
state.privacyLoadingState = RequestState.failed;
state.privacyError = error;
},
privacyUpdated(state, privacy) {
state.privacy = privacy;
state.privacyLoadingState = RequestState.succeeded;
state.privacyError = null;
state.privacyUpdated = true;
},
privacyUpdatingFailed(state, error) {
state.privacyLoadingState = RequestState.failed;
state.privacyError = error;
state.privacyUpdated = true;
} }
}, },
actions: { actions: {
@ -185,34 +223,20 @@ export default {
}); });
}); });
}, },
togglePrivacy(context, enabled) { updatePrivacy(context, privacy) {
return new Promise((resolve, reject)=>{ context.commit('privacyLoading');
if(enabled) { setPrivacy(localStorage.getItem('subscriberId'), privacy).then(()=>{
enablePrivacyCallBlocking(localStorage.getItem('subscriberId')).then(()=>{ context.commit('privacyUpdated', privacy);
context.commit('enablePrivacy'); }).catch((err)=>{
resolve(); context.commit('privacyUpdatingFailed', err.message);
}).catch((err)=>{
reject(err);
});
}
else {
disablePrivacyCallBlocking(localStorage.getItem('subscriberId')).then(()=>{
context.commit('disablePrivacy');
resolve();
}).catch((err)=>{
reject(err);
});
}
}); });
}, },
loadPrivacy(context) { loadPrivacy(context) {
return new Promise((resolve, reject)=>{ context.commit('privacyLoading');
getPrivacyCallBlocking(localStorage.getItem('subscriberId')).then((result)=>{ getPrivacyCallBlocking(localStorage.getItem('subscriberId')).then((privacy)=>{
context.commit('loadPrivacy', result); context.commit('privacyLoaded', privacy);
resolve(); }).catch((err)=>{
}).catch((err)=>{ context.commit('privacyLoadingFailed', err.message);
reject(err);
});
}); });
} }
} }

@ -62,12 +62,4 @@ describe('CallBlocking', function(){
assert.deepEqual(state.outgoingList, list); assert.deepEqual(state.outgoingList, list);
}); });
}); });
it('should enable/disable privacy call blocking', ()=>{
var state = {};
CallBlockingModule.mutations.enablePrivacy(state);
assert.equal(state.privacyEnabled, true);
CallBlockingModule.mutations.disablePrivacy(state);
assert.equal(state.privacyEnabled, false);
});
}); });

Loading…
Cancel
Save