mirror of
https://github.com/YunoHost/yunohost-admin.git
synced 2024-09-03 20:06:15 +02:00
moved objectToParams helper to api module to avoid 'store' import in a helper file
This commit is contained in:
parent
5c937a5352
commit
e2cdaa10be
7 changed files with 31 additions and 38 deletions
|
@ -5,7 +5,6 @@
|
|||
|
||||
import store from '@/store'
|
||||
import { openWebSocket, getResponseData, handleError } from './handlers'
|
||||
import { objectToParams } from '@/helpers/commons'
|
||||
|
||||
|
||||
/**
|
||||
|
@ -31,6 +30,31 @@ import { objectToParams } from '@/helpers/commons'
|
|||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Converts an object literal into an `URLSearchParams` that can be turned into a
|
||||
* query string or used as a body in a `fetch` call.
|
||||
*
|
||||
* @param {Object} obj - An object literal to convert.
|
||||
* @param {Object} options
|
||||
* @param {Boolean} [options.addLocale=false] - Option to append the locale to the query string.
|
||||
* @return {URLSearchParams}
|
||||
*/
|
||||
export function objectToParams (obj, { addLocale = false } = {}) {
|
||||
const urlParams = new URLSearchParams()
|
||||
for (const [key, value] of Object.entries(obj)) {
|
||||
if (Array.isArray(value)) {
|
||||
value.forEach(v => urlParams.append(key, v))
|
||||
} else {
|
||||
urlParams.append(key, value)
|
||||
}
|
||||
}
|
||||
if (addLocale) {
|
||||
urlParams.append('locale', store.getters.locale)
|
||||
}
|
||||
return urlParams
|
||||
}
|
||||
|
||||
|
||||
export default {
|
||||
options: {
|
||||
credentials: 'include',
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
export { default } from './api'
|
||||
export { default, objectToParams } from './api'
|
||||
export { handleError, registerGlobalErrorHandlers } from './handlers'
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
import store from '@/store'
|
||||
|
||||
|
||||
/**
|
||||
* Allow to set a timeout on a `Promise` expected response.
|
||||
* The returned Promise will be rejected if the original Promise is not resolved or
|
||||
|
@ -19,31 +16,6 @@ export function timeout (promise, delay) {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Converts an object literal into an `URLSearchParams` that can be turned into a
|
||||
* query string or used as a body in a `fetch` call.
|
||||
*
|
||||
* @param {Object} obj - An object literal to convert.
|
||||
* @param {Object} options
|
||||
* @param {Boolean} [options.addLocale=false] - Option to append the locale to the query string.
|
||||
* @return {URLSearchParams}
|
||||
*/
|
||||
export function objectToParams (obj, { addLocale = false } = {}) {
|
||||
const urlParams = new URLSearchParams()
|
||||
for (const [key, value] of Object.entries(obj)) {
|
||||
if (Array.isArray(value)) {
|
||||
value.forEach(v => urlParams.append(key, v))
|
||||
} else {
|
||||
urlParams.append(key, value)
|
||||
}
|
||||
}
|
||||
if (addLocale) {
|
||||
urlParams.append('locale', store.getters.locale)
|
||||
}
|
||||
return urlParams
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if passed value is an object literal.
|
||||
*
|
||||
|
|
|
@ -38,11 +38,10 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
import api from '@/api'
|
||||
import api, { objectToParams } from '@/api'
|
||||
import { validationMixin } from 'vuelidate'
|
||||
|
||||
import { formatI18nField, formatYunoHostArguments, formatFormData } from '@/helpers/yunohostArguments'
|
||||
import { objectToParams } from '@/helpers/commons'
|
||||
|
||||
export default {
|
||||
name: 'AppActions',
|
||||
|
|
|
@ -38,9 +38,8 @@
|
|||
import { validationMixin } from 'vuelidate'
|
||||
|
||||
// FIXME needs test and rework
|
||||
import api from '@/api'
|
||||
import api, { objectToParams } from '@/api'
|
||||
import { formatI18nField, formatYunoHostArguments, formatFormData } from '@/helpers/yunohostArguments'
|
||||
import { objectToParams } from '@/helpers/commons'
|
||||
|
||||
export default {
|
||||
name: 'AppConfigPanel',
|
||||
|
|
|
@ -49,8 +49,7 @@
|
|||
<script>
|
||||
import { validationMixin } from 'vuelidate'
|
||||
|
||||
import api from '@/api'
|
||||
import { objectToParams } from '@/helpers/commons'
|
||||
import api, { objectToParams } from '@/api'
|
||||
import { formatYunoHostArguments, formatI18nField, formatFormData } from '@/helpers/yunohostArguments'
|
||||
|
||||
export default {
|
||||
|
|
|
@ -60,8 +60,8 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
import api from '@/api'
|
||||
import { objectToParams, escapeHtml } from '@/helpers/commons'
|
||||
import api, { objectToParams } from '@/api'
|
||||
import { escapeHtml } from '@/helpers/commons'
|
||||
import { readableDate } from '@/helpers/filters/date'
|
||||
|
||||
export default {
|
||||
|
|
Loading…
Add table
Reference in a new issue