Skip to content

Commit

Permalink
code fixes for review
Browse files Browse the repository at this point in the history
  • Loading branch information
satkunas committed Apr 21, 2021
1 parent 62a1949 commit 80d25bb
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 36 deletions.
15 changes: 15 additions & 0 deletions html/pfappserver/root/src/utils/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,21 @@ Object.assign(apiCall, {
}]
})
},
optionsQuiet (url) {
return this.request({
method: 'options',
url: _encodeURL(url),
transformResponse: [data => {
let jsonData
try {
jsonData = JSON.parse(data)
} catch (e) {
jsonData = {}
}
return Object.assign({ quiet: true }, jsonData)
}]
})
},
patchQuiet (url, data) {
return this.request({
method: 'patch',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<b-card no-body>
<b-card-header>
<b-button-close @click="onClose" v-b-tooltip.hover.left.d300 :title="$t('Close [ESC]')"><icon name="times"/></b-button-close>
<h4 class="d-inline mb-0" v-html="title"/>
<b-badge v-if="titleBadge" class="ml-2" variant="secondary" v-t="titleBadge" />
<h4 class="d-inline mb-0" v-html="title.value"/>
<b-badge v-if="titleBadge" class="ml-2" variant="secondary" v-t="titleBadge.value" />
<slot name="headerAppend" v-if="$scopedSlots.headerAppend" v-bind="scopedSlotProps" />
</b-card-header>
<b-form @submit.prevent="onSave" ref="rootRef">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<b-card no-body>
<b-card-header>
<h4 class="d-inline mb-0" v-html="title"/>
<h4 class="d-inline mb-0" v-html="title.value"/>
<base-button-help v-if="titleHelp"
class="ml-1" :url="titleHelp" />
</b-card-header>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export const useViewCollectionItem = (collection, props, context) => {
// state
const form = ref({})
const meta = ref({})
const title = useItemTitle(props, context, form)
const titleBadge = useItemTitleBadge(props, context, form)
const title = computed(() => useItemTitle(props, context, form))
const titleBadge = computed(() => useItemTitleBadge(props, context, form))
const isModified = ref(false)

// unhandled custom props
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ref, watch } from '@vue/composition-api'
import { computed, ref, watch } from '@vue/composition-api'
import { useDebouncedWatchHandler } from '@/composables/useDebounce'
import useEventJail from '@/composables/useEventJail'

Expand All @@ -21,7 +21,7 @@ export const useViewCollectionItemFixed = (collection, props, context) => {

// state
const form = ref({})
const title = useItemTitle(props, context, form)
const title = computed(() => useItemTitle(props, context, form))
const isModified = ref(false)

// unhandled custom props
Expand Down
7 changes: 2 additions & 5 deletions html/pfappserver/root/src/views/Configuration/tenants/_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default {
})
},
listOptions: () => {
return apiCall.options('tenants').then(response => {
return apiCall.optionsQuiet('tenants').then(response => {
return response.data
})
},
Expand All @@ -17,7 +17,7 @@ export default {
})
},
itemOptions: id => {
return apiCall.options(['tenant', id]).then(response => {
return apiCall.optionsQuiet(['tenant', id]).then(response => {
return response.data
})
},
Expand All @@ -34,9 +34,6 @@ export default {
delete: id => {
return apiCall.delete(['tenant', id])
},
reassign: data => {
return apiCall.patch(['tenant', data.from, 'reassign'], { id: data.to })
},
search: data => {
return apiCall.post('tenants/search', data).then(response => {
return response.data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
</div>
<h4 class="mb-0">
{{ $t('Tenants') }}
<pf-button-help class="ml-1" url="PacketFence_Installation_Guide.html#tenants" />
<pf-button-help class="ml-1" url="PacketFence_Installation_Guide.html#_tenants" />
</h4>
</b-card-header>
</b-card-header>
<div class="card-body">
<transition name="fade" mode="out-in">
<div v-if="advancedMode">
<b-form @submit.prevent="onSearchAdvanced" @reset.prevent="onSearchReset">
<base-search-input-advanced
<base-search-input-advanced
v-model="conditionAdvanced"
:disabled="isLoading"
:fields="fields"
Expand All @@ -26,8 +26,8 @@
/>
<b-container fluid class="text-right mt-3 px-0">
<b-button class="mr-1" type="reset" variant="secondary" :disabled="isLoading">{{ $t('Clear') }}</b-button>
<base-button-save-search
save-search-namespace="tenants-advanced"
<base-button-save-search
save-search-namespace="tenants-advanced"
v-model="conditionAdvanced"
:disabled="isLoading"
@search="onSearchAdvanced"
Expand All @@ -53,29 +53,29 @@
</b-row>
<b-row align-h="end" align-v="center">
<b-col>
<base-search-input-columns
<base-search-input-columns
v-model="columns"
:disabled="isLoading"
/>
</b-col>
<b-col cols="auto">
<b-container fluid>
<b-row align-v="center">
<base-search-input-limit
<base-search-input-limit
v-model="limit"
size="md"
:limits="limits"
:disabled="isLoading"
/>
<base-search-input-page
<base-search-input-page
v-model="page"
:limit="limit"
:total-rows="totalRows"
:disabled="isLoading"
/>
<base-button-export-csv
<base-button-export-csv
class="mb-3" size="md"
:filename="`${$route.path.slice(1).replace('/', '-')}.csv`"
:filename="`${$route.path.slice(1).replace('/', '-')}.csv`"
:disabled="isLoading"
:columns="columns" :data="items"
/>
Expand Down Expand Up @@ -114,7 +114,7 @@
>{{ $t('Delete') }}</base-button-confirm>
<b-button size="sm" variant="outline-primary" class="mr-1" @click.stop.prevent="onClone(item.id)">{{ $t('Clone') }}</b-button>
</span>
</template>
</template>
</b-table>
</div>
</b-card>
Expand Down Expand Up @@ -165,15 +165,12 @@ const setup = (props, context) => {
doReset,
doSearchString,
doSearchCondition,
reSearch,
items,
sortBy,
sortDesc
reSearch
} = search
onMounted(() => {
const { currentRoute: { query: { query } = {} } = {} } = $router
if (query) {
if (query) {
const parsedQuery = JSON.parse(query)
switch(parsedQuery.constructor) {
case Array: // advanced search
Expand Down Expand Up @@ -249,9 +246,6 @@ const setup = (props, context) => {
onSearchAdvanced,
onSearchReset,
onRowClicked,
items,
sortBy,
sortDesc,
onClone,
onRemove,
...search
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@ import {
defaultsFromMeta as useItemDefaults
} from '../../_config/'

const useItemTitle = (props) => {
const useItemTitle = (props, context) => {
const {
id,
isClone,
isNew
} = toRefs(props)
const { root: { $store } = {} } = context
const { [id.value]: { name } = {} } = $store.getters['$_tenants/all'] // use store, not form
return computed(() => {
switch (true) {
case !isNew.value && !isClone.value:
return i18n.t('Tenant <code>{id}</code>', { id: id.value })
return i18n.t('Tenant <code>{name}</code>', { name })
case isClone.value:
return i18n.t('Clone Tenant <code>{id}</code>', { id: id.value })
return i18n.t('Clone Tenant <code>{name}</code>', { name })
default:
return i18n.t('New Tenant')
}
Expand Down Expand Up @@ -47,7 +49,8 @@ const useStore = (props, context, form) => {
getOptions: () => $store.dispatch('$_tenants/options'),
createItem: () => $store.dispatch('$_tenants/createTenant', form.value),
deleteItem: () => $store.dispatch('$_tenants/deleteTenant', id.value),
getItem: () => $store.dispatch('$_tenants/getTenant', id.value).then(item => {
getItem: () => $store.dispatch('$_tenants/getTenant', id.value).then(_item => {
let item = { ..._item } // dereference
if (isClone.value) {
item.name = `${item.name}-${i18n.t('copy')}`
item.not_deletable = false
Expand All @@ -67,7 +70,7 @@ import {
fields
} from '../config'
export const useSearch = (props, context, options) => {
return useConfigurationSearch(api, {
return useConfigurationSearch(api, {
name: 'tenants', // localStorage prefix
columns,
fields,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const state = () => {
}

const getters = {
all: state => state.cache,
isWaiting: state => [types.LOADING, types.DELETING].includes(state.itemStatus),
isLoading: state => state.itemStatus === types.LOADING
}
Expand Down

0 comments on commit 80d25bb

Please sign in to comment.