Bladeren bron

add/remove filter lists now working

pull/1/head
Jonathan Cobb 4 jaren geleden
bovenliggende
commit
ff3bd7b442
3 gewijzigde bestanden met toevoegingen van 86 en 8 verwijderingen
  1. +6
    -1
      src/_services/app.service.js
  2. +21
    -0
      src/_store/apps.module.js
  3. +59
    -7
      src/account/AppConfigPage.vue

+ 6
- 1
src/_services/app.service.js Bestand weergeven

@@ -21,7 +21,8 @@ export const appService = {
takeDataAction,

getAppConfigViewByUserId,
takeConfigItemAction
takeConfigItemAction,
takeConfigAppAction
};

// MITM
@@ -92,3 +93,7 @@ function getAppConfigViewByUserId(userId, appId, viewId, messages, errors) {
function takeConfigItemAction(userId, appId, viewId, itemId, params, action, messages, errors) {
return fetch(`${config.apiUrl}/users/${userId}/apps/${appId}/config/${viewId}/actions/${action}?id=${itemId}`, util.postWithAuth(params)).then(util.handleCrudResponse(messages, errors));
}

function takeConfigAppAction(userId, appId, viewId, params, action, messages, errors) {
return fetch(`${config.apiUrl}/users/${userId}/apps/${appId}/config/${viewId}/actions/${action}`, util.putWithAuth(params)).then(util.handleCrudResponse(messages, errors));
}

+ 21
- 0
src/_store/apps.module.js Bestand weergeven

@@ -171,6 +171,15 @@ const actions = {
actionResult => commit('takeConfigItemActionSuccess', actionResult),
error => commit('takeConfigItemActionFailure', error)
);
},

takeConfigAppAction({ commit }, {userId, appId, viewId, params, action, messages, errors}) {
commit('takeConfigAppActionRequest');
appService.takeConfigAppAction(userId, appId, viewId, params, action, messages, errors)
.then(
actionResult => commit('takeConfigAppActionSuccess', actionResult),
error => commit('takeConfigAppActionFailure', error)
);
}
};

@@ -376,6 +385,18 @@ const mutations = {
takeConfigItemActionFailure(state, error) {
state.loading.action = false;
state.error = error;
},

takeConfigAppActionRequest(state) {
state.loading.action = true;
},
takeConfigAppActionSuccess(state, actionResult) {
state.loading.action = false;
state.actionResult = actionResult;
},
takeConfigAppActionFailure(state, error) {
state.loading.action = false;
state.error = error;
}
};



+ 59
- 7
src/account/AppConfigPage.vue Bestand weergeven

@@ -5,7 +5,7 @@
<div v-if="loading()">
{{messages.loading_app_config_data}}
</div>
<div v-else-if="appConfigData && appConfigData.length && appConfigData.length > 0 && configView">
<div v-else-if="appConfigData && configView">

<!-- table of results -->
<table border="1" v-if="appConfigData instanceof Array">
@@ -58,12 +58,36 @@
</tbody>

</table>

<!-- single item view -->
<!-- single item view -->
<table border="1" v-else>

</table>

<!-- app-scoped actions -->
<div v-for="action in appActions">

<!-- actions with parameters: show a form -->
<div v-if="typeof action.params !== 'undefined' || action.params !== null || action.params.length > 0">
<h4>{{messages['app_'+app.name+'_config_action_'+action.name]}}</h4>
<form @submit.prevent="appAction(action)">

<div v-for="param in action.params" class="form-group">
<label :htmlFor="param.name">{{messages['app_'+app.name+'_config_field_'+param.name]}}</label>
<input v-model="appActionParams[action.name][param.name]" :name="param.name" class="form-control"/>
<small v-if="messages['app_'+app.name+'_config_field_'+param.name+'_description'].length > 0">{{messages['app_'+app.name+'_config_field_'+param.name+'_description']}}</small>
<div v-if="errors.has(param.name)" class="invalid-feedback d-block">{{ errors.first(param.name) }}</div>
</div>

<button class="btn btn-primary" :disabled="loading()">{{messages['app_'+app.name+'_config_button_'+action.name]}}</button>
</form>
</div>

<!-- actions with no parameters: just a button -->
<div v-else>
<button class="btn btn-primary" :disabled="loading()">{{messages['app_'+app.name+'_config_action_'+action.name]}}</button>
</div>
</div>

</div>
<div v-else>
{{messages.message_no_config_data}}
@@ -86,7 +110,9 @@
appFields: null,
configView: null,
itemActions: null,
appActions: null
appActions: null,
itemActionParams: {},
appActionParams: {}
};
},
computed: {
@@ -112,20 +138,31 @@
},
methods: {
...mapActions('apps', [
'getAppByUserId', 'getAppConfigViewByUserId', 'takeConfigItemAction'
'getAppByUserId', 'getAppConfigViewByUserId', 'takeConfigItemAction', 'takeConfigAppAction'
]),
...mapGetters('apps', ['loading']),
actionIsAvailable(action, row) {
if (typeof action.when === 'undefined' || action.when === null) return true;
return safeEval(action.when, {'item': row}) === true;
},
itemAction(action, itemId, params) {
itemAction(action, itemId) {
this.takeConfigItemAction({
userId: this.user.name,
appId: this.appId,
viewId: this.viewId,
itemId: itemId,
params: (typeof params === 'undefined' || params === null ? {} : params),
params: this.itemActionParams[action.name],
action: action.name,
messages: this.messages,
errors: this.errors
});
},
appAction(action) {
this.takeConfigAppAction({
userId: this.user.name,
appId: this.appId,
viewId: this.viewId,
params: this.appActionParams[action.name],
action: action.name,
messages: this.messages,
errors: this.errors
@@ -153,8 +190,10 @@
const action = this.configView.actions[j];
if (action.scope === 'item') {
itemActions.push(action);
this.itemActionParams[action.name] = {};
} else if (action.scope === 'app') {
appActions.push(action);
this.appActionParams[action.name] = {};
} else {
console.warn('invalid scope for action: '+action.scope);
}
@@ -169,6 +208,19 @@
},
actionResult (ar) {
if (ar) {
console.log('clearing form fields...');
for (let action in this.itemActionParams) {
if (this.itemActionParams.hasOwnProperty(action)) {
this.itemActionParams[action] = {};
}
}

for (let action in this.appActionParams) {
if (this.appActionParams.hasOwnProperty(action)) {
this.appActionParams[action] = {};
}
}

this.getAppConfigViewByUserId({
userId: this.user.uuid,
appId: this.appId,


Laden…
Annuleren
Opslaan