Our nightly tests flagged the fact that
the feature was unstable and unrealiable.
Changes:
* Extract subscriber phonebook api and state
* Change direct use of http in the sub-phonebook
method to use the relevant method in common.js
* Simplify logic to PATCH single properties
with a unique PUT in the Phonebook entry form
* Amend getList, handleResponseError and
put to allow use with API v2 endpoints
* Amend translations and methods to replace
"phonebook" with "phonebook entry" where
necessary
Change-Id: I189d45fe426a1ded400a251d7efdfa72f76f9061
(cherry picked from commit ff40864da0)
mr12.5
parent
3433a194b9
commit
8eb8cfb10d
@ -0,0 +1,65 @@
|
|||||||
|
import {
|
||||||
|
del,
|
||||||
|
get,
|
||||||
|
getList,
|
||||||
|
patchReplace,
|
||||||
|
post,
|
||||||
|
putMinimal
|
||||||
|
} from 'src/api/common'
|
||||||
|
|
||||||
|
export async function createPhonebook (data) {
|
||||||
|
const payload = {
|
||||||
|
name: data.name,
|
||||||
|
number: data.number,
|
||||||
|
shared: data.shared,
|
||||||
|
subscriber_id: Number(data.subscriber_id)
|
||||||
|
}
|
||||||
|
return post({
|
||||||
|
resource: 'subscriberphonebookentries',
|
||||||
|
body: payload
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function deleteEntry (id) {
|
||||||
|
return del({
|
||||||
|
resource: 'subscriberphonebookentries',
|
||||||
|
resourceId: id
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getEntryById (id) {
|
||||||
|
return get({
|
||||||
|
resource: 'subscriberphonebookentries',
|
||||||
|
resourceId: id
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getPhonebook (options) {
|
||||||
|
return getList({
|
||||||
|
resource: 'subscriberphonebookentries',
|
||||||
|
params: options,
|
||||||
|
...(options.rows === 0 ? { all: true } : {})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function setSharedValue (id, value) {
|
||||||
|
return patchReplace({
|
||||||
|
resource: 'subscriberphonebookentries',
|
||||||
|
resourceId: id,
|
||||||
|
fieldPath: 'shared',
|
||||||
|
value
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function updateEntry (data) {
|
||||||
|
return putMinimal({
|
||||||
|
resource: 'subscriberphonebookentries',
|
||||||
|
resourceId: data.id,
|
||||||
|
body: {
|
||||||
|
number: data.number,
|
||||||
|
shared: data.shared,
|
||||||
|
name: data.name,
|
||||||
|
subscriber_id: Number(data.subscriberId)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
@ -0,0 +1,91 @@
|
|||||||
|
import { LIST_DEFAULT_ROWS } from 'src/api/common'
|
||||||
|
import {
|
||||||
|
createPhonebook,
|
||||||
|
deleteEntry,
|
||||||
|
getEntryById,
|
||||||
|
getPhonebook,
|
||||||
|
setSharedValue,
|
||||||
|
updateEntry
|
||||||
|
} from 'src/api/subscriber-phonebook'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
namespaced: true,
|
||||||
|
state: {
|
||||||
|
phonebookRows: [],
|
||||||
|
pagination: {
|
||||||
|
sortBy: 'id',
|
||||||
|
descending: false,
|
||||||
|
page: 1,
|
||||||
|
rowsPerPage: LIST_DEFAULT_ROWS,
|
||||||
|
rowsNumber: 0
|
||||||
|
},
|
||||||
|
numberInput: null
|
||||||
|
},
|
||||||
|
getters: {
|
||||||
|
getEntryById: (state) => (id) => {
|
||||||
|
return state.phonebookRows.find((entry) => entry.id === id)
|
||||||
|
},
|
||||||
|
getPrefilledNumber: (state) => state.numberInput,
|
||||||
|
phonebookRows: (state) => state.phonebookRows,
|
||||||
|
pagination: (state) => state.pagination
|
||||||
|
},
|
||||||
|
mutations: {
|
||||||
|
setPhonebookRows (state, rows) {
|
||||||
|
state.phonebookRows = rows
|
||||||
|
},
|
||||||
|
setPagination (state, pagination) {
|
||||||
|
state.pagination = { ...state.pagination, ...pagination }
|
||||||
|
},
|
||||||
|
setSharedValue (state, { id, value }) {
|
||||||
|
const rowIndex = state.phonebookRows.findIndex((row) => row.id === id)
|
||||||
|
if (rowIndex > -1) {
|
||||||
|
state.phonebookRows[rowIndex].shared = value
|
||||||
|
}
|
||||||
|
},
|
||||||
|
setNumber (state, numberInput) {
|
||||||
|
state.numberInput = numberInput
|
||||||
|
}
|
||||||
|
},
|
||||||
|
actions: {
|
||||||
|
async loadPhonebook ({ commit }, options) {
|
||||||
|
try {
|
||||||
|
const list = await getPhonebook({
|
||||||
|
...options
|
||||||
|
})
|
||||||
|
commit('setPhonebookRows', list.items || [])
|
||||||
|
commit('setPagination', {
|
||||||
|
page: options.page,
|
||||||
|
rowsPerPage: options.rows,
|
||||||
|
rowsNumber: list.totalCount
|
||||||
|
})
|
||||||
|
return list
|
||||||
|
} catch (err) {
|
||||||
|
commit('setPhonebookRows', [])
|
||||||
|
throw err
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async removeEntry (context, id) {
|
||||||
|
await deleteEntry(id)
|
||||||
|
},
|
||||||
|
async getEntry (context, id) {
|
||||||
|
const cachedEntry = context.getters.getEntryById(id)
|
||||||
|
if (cachedEntry) {
|
||||||
|
return cachedEntry
|
||||||
|
}
|
||||||
|
// Fetch from API if not in store
|
||||||
|
const response = await getEntryById(id)
|
||||||
|
return response
|
||||||
|
},
|
||||||
|
async createPhonebook (context, data) {
|
||||||
|
await createPhonebook(data)
|
||||||
|
},
|
||||||
|
async updateEntry (context, data) {
|
||||||
|
await updateEntry(data)
|
||||||
|
},
|
||||||
|
async updateSharedValue (context, row) {
|
||||||
|
const newValue = !row.shared
|
||||||
|
context.commit('setSharedValue', { id: row.id, value: newValue })
|
||||||
|
await setSharedValue(row.id, newValue)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in new issue