diff options
Diffstat (limited to 'front/odiparpack/app/utils')
| -rw-r--r-- | front/odiparpack/app/utils/odipar/api.js | 101 | ||||
| -rw-r--r-- | front/odiparpack/app/utils/odipar/constants.js | 9 | ||||
| -rw-r--r-- | front/odiparpack/app/utils/odipar/menu.js | 51 | 
3 files changed, 161 insertions, 0 deletions
| diff --git a/front/odiparpack/app/utils/odipar/api.js b/front/odiparpack/app/utils/odipar/api.js new file mode 100644 index 0000000..50c2beb --- /dev/null +++ b/front/odiparpack/app/utils/odipar/api.js @@ -0,0 +1,101 @@ +import axios from 'axios' +import {apiUrl} from './constants'; +import qs from "query-string"; +import { openSuccessMessage, openErrorMessage } from 'ba-actions/message'; + +export function getHeaders() { +	let session = getSession(); +	return { +		//Authorization: `Token ${(session && session.accessToken) || null}` +	} +} + + +export function getSession() { +	if (window && window.localStorage) { +		return window.localStorage.getObject('session'); +	} + +	return null; +} + +export function saveSession(value) { +	if (window && window.localStorage) { +		return window.localStorage.saveObject('session', value); +	} + +	return null; +} + +export function apiReq(endPoint, data, method, headers, requestOptions = {}) { +		//console.log("apiReq - ANTES DE PROMESA") +		headers = { +			...headers +		} +		if (method === 'get' || method === 'delete') { +			data = { +				...requestOptions, +				params: data, +				paramsSerializer: function (params) { +					return qs.stringify(params, { arrayFormat: 'repeat' }) +				}, +				headers +			} +		} + +		return axios[method](endPoint, data, { headers }) +} + +export function generateUrl(path) { +    return apiUrl + path; +} + +export function apiPost(endPoint, data, headers = {}) { +	return apiReq(generateUrl(endPoint), data, 'post', headers); +} + +export function apiDelete(endPoint, data, headers = {}) { +	return apiReq(generateUrl(endPoint), data, 'delete', headers); +} + +export function apiGet(endPoint, data, headers = {}, requestOptions) { +    return apiReq(generateUrl(endPoint), data, 'get', headers, requestOptions); +} + +export function apiPut(endPoint, data, headers = {}) { +	return apiReq(generateUrl(endPoint), data, 'put', headers); +} + + +export function addMessageCurry(promise, dispatch, errorMsg = '', successMsg = '', showError = true) { +	return new Promise( +		(resolve, reject) => { + +			promise +				.then(response => { + +					if (successMsg) { +						console.log("addMessageCurry -SUCCESS MSG") +						dispatch( +							openSuccessMessage(successMsg) +						) +					} + +					resolve(response) +				}) +				.catch( +					err => { +						if(showError) { +							 dispatch( +								openErrorMessage(errorMsg || ((err.response && err.response.data.message) || 'Server encountered an error')) +							) +						} + +						reject(err) +					} +				) + +		} +	) + +}
\ No newline at end of file diff --git a/front/odiparpack/app/utils/odipar/constants.js b/front/odiparpack/app/utils/odipar/constants.js new file mode 100644 index 0000000..73f3521 --- /dev/null +++ b/front/odiparpack/app/utils/odipar/constants.js @@ -0,0 +1,9 @@ +//export const apiUrl = `${config.api}api/v1/`; +export const apiUrl = 'http://localhost:8083/'; + +//mensaje  +export function partial(fn, ...presetArgs) { +    return function partiallyApplied(...laterArgs) { +      return fn(...presetArgs, ...laterArgs); +    }; +}
\ No newline at end of file diff --git a/front/odiparpack/app/utils/odipar/menu.js b/front/odiparpack/app/utils/odipar/menu.js new file mode 100644 index 0000000..1b280b8 --- /dev/null +++ b/front/odiparpack/app/utils/odipar/menu.js @@ -0,0 +1,51 @@ +module.exports = [ +    { +      key: 'seguimiento', +      name: 'Seguimiento', +      icon: 'near_me', +      link: '/app/dashboard-v2', +      child: [ ] +    }, +    { +      key: 'pedidos', +      name: 'Pedidos', +      icon: 'inventory_2', +      link: '/app/pedidos', +      child: [ ] +    }, +    { +      key: 'camiones', +      name: 'Camiones', +      icon: 'local_shipping', +      link: '/app/layouts/grid', +      child: [ ] +    }, +    { +      key: 'almacenes', +      name: 'Almacenes', +      icon: 'warehouse', +      link: '/app/almacenes', +      child: [ ] +    }, +    { +      key: 'red_tramos', +      name: 'Red de Tramos', +      icon: 'location_on', +      link: '/app/forms/reduxform', +      child: [ ] +    }, +    { +      key: 'otros', +      name: 'Otros parámetros', +      icon: 'settings', +      link: '/app/ui/icons', +      child: [ ] +    }, +    { +      key: 'simulacion', +      name: 'Simulación', +      icon: 'fast_forward', +      link: '/app/pages/calendar', +      child: [ ] +    } +  ];
\ No newline at end of file | 
