diff --git a/site/config/config.php b/site/config/config.php
index f38232d..a2f026f 100644
--- a/site/config/config.php
+++ b/site/config/config.php
@@ -36,6 +36,7 @@ return [
require_once(__DIR__ . '/routes/mapado-api.php'),
require_once(__DIR__ . '/routes/month-dates.php'),
require_once(__DIR__ . '/routes/update-mapado-event.php'),
+ require_once(__DIR__ . '/routes/mapado-fetch.php'),
],
'hooks' => [
'page.update:after' => require_once(__DIR__ . '/hooks/update-mapado-event.php')
diff --git a/site/config/routes/mapado-fetch.php b/site/config/routes/mapado-fetch.php
new file mode 100644
index 0000000..b530311
--- /dev/null
+++ b/site/config/routes/mapado-fetch.php
@@ -0,0 +1,25 @@
+ '/mapado-fetch.json',
+ 'method' => 'POST',
+ 'action' => function() {
+ $jsonRequest = file_get_contents("php://input");
+ $request = json_decode($jsonRequest, true);
+ $requestUrl = $request['requestUrl'];
+
+ $token = site()->mapadoToken();
+
+ $ch = curl_init();
+ curl_setopt($ch, CURLOPT_URL, $requestUrl);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($ch, CURLOPT_HTTPHEADER, [
+ "Authorization: Bearer " . $token
+ ]);
+
+ $responseString = curl_exec($ch);
+ curl_close($ch);
+
+ return $responseString;
+ }
+];
\ No newline at end of file
diff --git a/site/plugins/mapado-check/index.css b/site/plugins/mapado-check/index.css
index e8e75e5..ae60d99 100644
--- a/site/plugins/mapado-check/index.css
+++ b/site/plugins/mapado-check/index.css
@@ -1,4 +1 @@
-
-button[data-v-402405a5] {
- margin-top: 2rem;
-}
+button[data-v-36712d5e]{margin-top:2rem}
diff --git a/site/plugins/mapado-check/index.js b/site/plugins/mapado-check/index.js
index 83d4987..af00c2c 100644
--- a/site/plugins/mapado-check/index.js
+++ b/site/plugins/mapado-check/index.js
@@ -1,117 +1 @@
-(function() {
- "use strict";
- function normalizeComponent(scriptExports, render, staticRenderFns, functionalTemplate, injectStyles, scopeId, moduleIdentifier, shadowMode) {
- var options = typeof scriptExports === "function" ? scriptExports.options : scriptExports;
- if (render) {
- options.render = render;
- options.staticRenderFns = staticRenderFns;
- options._compiled = true;
- }
- {
- options._scopeId = "data-v-" + scopeId;
- }
- return {
- exports: scriptExports,
- options
- };
- }
- const _sfc_main = {
- __name: "MapadoCheckButton",
- props: {
- mapadoToken: String
- },
- setup(__props) {
- const { mapadoToken } = __props;
- const id = Vue.ref(null);
- const icon = Vue.ref("search");
- const theme = Vue.ref(null);
- const text = Vue.ref("Vérifie si Mapado contient bien un événement correspondant.");
- setTimeout(() => {
- const idInput = document.querySelector(".k-field-name-mapadoid input");
- id.value = idInput.value;
- idInput.addEventListener("input", () => {
- id.value = idInput.value;
- });
- }, 100);
- function formatDateString(inputString) {
- const splitString = inputString.split(" ");
- const startDay = splitString[2];
- const startMonth = splitString[3];
- const startYear = splitString[4];
- const endDay = splitString[9];
- const endMonth = splitString[10];
- const endYear = splitString[11];
- const formattedString = `du ${startDay} ${startMonth} ${startYear} au ${endDay} ${endMonth} ${endYear}`;
- return formattedString;
- }
- function connect() {
- icon.value = "loader";
- theme.value = "yellow";
- const myHeaders = new Headers();
- myHeaders.append("Authorization", "Bearer " + mapadoToken);
- const requestOptions = {
- method: "GET",
- headers: myHeaders,
- redirect: "follow"
- };
- fetch(
- "https://ticketing.mapado.net/v1/ticketings/" + id.value + "?fields=id,title,slug,sellingDeviceSchedule",
- requestOptions
- ).then((response) => {
- console.log(response);
- if (response.status === 404) {
- throw new Error(
- "Aucun événement ne correspond à l'identifiant : " + id.value + "."
- );
- }
- if (response.status === 500) {
- throw new Error(
- "Impossible de joindre le serveur Mapado. Veuillez réessayer plus tard."
- );
- }
- return response.json();
- }).then((result) => {
- icon.value = "check";
- theme.value = "green";
- const scheduleFirstKey = Object.keys(result.sellingDeviceSchedule)[0];
- const schedule = formatDateString(
- result.sellingDeviceSchedule[scheduleFirstKey].fr.toLowerCase()
- );
- console.log(result);
- text.value = `Événement correspondant sur Mapado : ${result.title}, ${schedule} (gérer sur Mapado.).`;
- }).catch((error) => {
- icon.value = "alert";
- theme.value = "red";
- text.value = "" + error + "";
- console.log(error);
- setTimeout(() => {
- icon.value = "search";
- theme.value = null;
- }, 2e3);
- });
- }
- return { __sfc: true, id, icon, theme, text, formatDateString, connect };
- }
- };
- var _sfc_render = function render() {
- var _vm = this, _c = _vm._self._c, _setup = _vm._self._setupProxy;
- return _c("div", { staticClass: "k-number-field k-field k-field-name-mapadoid" }, [_c("k-button", { attrs: { "variant": "filled", "theme": _setup.theme, "icon": _setup.icon }, on: { "click": _setup.connect } }, [_vm._v("Vérifier")]), _c("footer", { staticClass: "k-field-footer" }, [_c("div", { staticClass: "k-help k-field-help k-text" }, [_c("p", { domProps: { "innerHTML": _vm._s(_setup.text) } })])])], 1);
- };
- var _sfc_staticRenderFns = [];
- _sfc_render._withStripped = true;
- var __component__ = /* @__PURE__ */ normalizeComponent(
- _sfc_main,
- _sfc_render,
- _sfc_staticRenderFns,
- false,
- null,
- "402405a5"
- );
- __component__.options.__file = "/Users/adrienpayet/code/ntb/site/plugins/mapado-check/src/components/MapadoCheckButton.vue";
- const MapadoCheckButton = __component__.exports;
- window.panel.plugin("adrienpayet/mapado-check", {
- fields: {
- "mapado-check": MapadoCheckButton
- }
- });
-})();
+(function(){"use strict";function f(i,e,o,a,r,c,d,s){var t=typeof i=="function"?i.options:i;return e&&(t.render=e,t.staticRenderFns=o,t._compiled=!0),t._scopeId="data-v-"+c,{exports:i,options:t}}const p={__name:"MapadoCheckButton",props:{mapadoToken:String},setup(i){const e=Vue.ref(null),o=Vue.ref("search"),a=Vue.ref(null),r=Vue.ref("Vérifie si Mapado contient bien un événement correspondant.");setTimeout(()=>{const s=document.querySelector(".k-field-name-mapadoid input");e.value=s.value,s.addEventListener("input",()=>{e.value=s.value})},100);function c(s){const t=s.split(" "),n=t[2],l=t[3],u=t[4],g=t[9],k=t[10],y=t[11];return`du ${n} ${l} ${u} au ${g} ${k} ${y}`}function d(){o.value="loader",a.value="yellow";const s="https://ticketing.mapado.net/v1/ticketings/"+e.value+"?fields=id,title,slug,sellingDeviceSchedule",t={method:"POST",body:JSON.stringify({requestUrl:s})};fetch("/mapado-fetch.json",t).then(n=>{if(console.log(n),n.status===404)throw new Error("Aucun événement ne correspond à l'identifiant : "+e.value+".");if(n.status===500)throw new Error("Impossible de joindre le serveur Mapado. Veuillez réessayer plus tard.");return n.json()}).then(n=>{o.value="check",a.value="green";const l=Object.keys(n.sellingDeviceSchedule)[0],u=c(n.sellingDeviceSchedule[l].fr.toLowerCase());console.log(n),r.value=`Événement correspondant sur Mapado : ${n.title}, ${u} (gérer sur Mapado.).`}).catch(n=>{o.value="alert",a.value="red",r.value=""+n+"",console.log(n),setTimeout(()=>{o.value="search",a.value=null},2e3)})}return{__sfc:!0,id:e,icon:o,theme:a,text:r,formatDateString:c,connect:d}}};var m=function(){var e=this,o=e._self._c,a=e._self._setupProxy;return o("div",{staticClass:"k-number-field k-field k-field-name-mapadoid"},[o("k-button",{attrs:{variant:"filled",theme:a.theme,icon:a.icon},on:{click:a.connect}},[e._v("Vérifier")]),o("footer",{staticClass:"k-field-footer"},[o("div",{staticClass:"k-help k-field-help k-text"},[o("p",{domProps:{innerHTML:e._s(a.text)}})])])],1)},v=[],h=f(p,m,v,!1,null,"36712d5e");const _=h.exports;window.panel.plugin("adrienpayet/mapado-check",{fields:{"mapado-check":_}})})();
diff --git a/site/plugins/mapado-check/src/components/MapadoCheckButton.vue b/site/plugins/mapado-check/src/components/MapadoCheckButton.vue
index 6d115eb..37d60f6 100755
--- a/site/plugins/mapado-check/src/components/MapadoCheckButton.vue
+++ b/site/plugins/mapado-check/src/components/MapadoCheckButton.vue
@@ -54,21 +54,19 @@ function connect() {
icon.value = "loader";
theme.value = "yellow";
- const myHeaders = new Headers();
- myHeaders.append("Authorization", "Bearer " + mapadoToken);
+ const requestUrl =
+ "https://ticketing.mapado.net/v1/ticketings/" +
+ id.value +
+ "?fields=id,title,slug,sellingDeviceSchedule";
const requestOptions = {
- method: "GET",
- headers: myHeaders,
- redirect: "follow",
+ method: "POST",
+ body: JSON.stringify({
+ requestUrl,
+ }),
};
- fetch(
- "https://ticketing.mapado.net/v1/ticketings/" +
- id.value +
- "?fields=id,title,slug,sellingDeviceSchedule",
- requestOptions
- )
+ fetch("/mapado-fetch.json", requestOptions)
.then((response) => {
console.log(response);
if (response.status === 404) {
@@ -98,7 +96,6 @@ function connect() {
theme.value = "red";
text.value = "" + error + "";
console.log(error);
-
setTimeout(() => {
icon.value = "search";
theme.value = null;