diff --git a/src/Bundle/ChillTicketBundle/src/Resources/public/vuejs/TicketApp/App.vue b/src/Bundle/ChillTicketBundle/src/Resources/public/vuejs/TicketApp/App.vue index 89210e057..19989d16f 100644 --- a/src/Bundle/ChillTicketBundle/src/Resources/public/vuejs/TicketApp/App.vue +++ b/src/Bundle/ChillTicketBundle/src/Resources/public/vuejs/TicketApp/App.vue @@ -1,11 +1,50 @@ - -{{ $t('hello', {'name': 'Boris'})}} + + {{ ticket.externalRef }} + {{ ticket.currentMotive }} + + + + {{ person.firstName }} + {{ person.lastName }} + + + {{ ticket_history_line.event_type}} + {{ ticket_history_line.data}} + + - diff --git a/src/Bundle/ChillTicketBundle/src/Resources/public/vuejs/TicketApp/index.ts b/src/Bundle/ChillTicketBundle/src/Resources/public/vuejs/TicketApp/index.ts index c72576af5..182925b92 100644 --- a/src/Bundle/ChillTicketBundle/src/Resources/public/vuejs/TicketApp/index.ts +++ b/src/Bundle/ChillTicketBundle/src/Resources/public/vuejs/TicketApp/index.ts @@ -1,10 +1,13 @@ +import App from './App.vue'; import {createApp} from "vue"; + import { _createI18n } from "../../../../../../ChillMainBundle/Resources/public/vuejs/_js/i18n"; +import {messages} from "./i18n/messages"; + import VueToast from 'vue-toast-notification'; import 'vue-toast-notification/dist/theme-sugar.css'; -import {messages} from "./i18n/messages"; -import App from './App.vue'; -import {Ticket} from "../../types"; + +import { store } from "./store"; declare global { interface Window { @@ -12,25 +15,12 @@ declare global { } } -const i18n = _createI18n(messages) - -// the initial ticket is serialized there: -console.log(window.initialTicket); -// to have js object -const ticket = JSON.parse(window.initialTicket) as Ticket; -console.log("the ticket for this app (at page loading)", ticket); - -for (const eh of ticket.history) { - if (eh.event_type === 'add_person') { - console.log("add_person", eh.data.person); - } else if (eh.event_type === 'set_motive') { - console.log("set_motive", eh.data.motive); - } -} +const i18n = _createI18n(messages); const _app = createApp({ template: '', }) + .use(store) .use(i18n) .use(VueToast) .component('app', App) diff --git a/src/Bundle/ChillTicketBundle/src/Resources/public/vuejs/TicketApp/store/index.ts b/src/Bundle/ChillTicketBundle/src/Resources/public/vuejs/TicketApp/store/index.ts new file mode 100644 index 000000000..013a6d68a --- /dev/null +++ b/src/Bundle/ChillTicketBundle/src/Resources/public/vuejs/TicketApp/store/index.ts @@ -0,0 +1,12 @@ +import { createStore } from "vuex"; +import { State as MotiveStates, moduleMotive } from "./modules/motive"; + +export type RootState = { + motive: MotiveStates; + }; + +export const store = createStore({ + modules: { + motive:moduleMotive, + } +}); diff --git a/src/Bundle/ChillTicketBundle/src/Resources/public/vuejs/TicketApp/store/modules/motive.ts b/src/Bundle/ChillTicketBundle/src/Resources/public/vuejs/TicketApp/store/modules/motive.ts new file mode 100644 index 000000000..85aa0e36c --- /dev/null +++ b/src/Bundle/ChillTicketBundle/src/Resources/public/vuejs/TicketApp/store/modules/motive.ts @@ -0,0 +1,47 @@ +import { fetchResults, makeFetch } from "../../../../../../../../ChillMainBundle/Resources/public/lib/api/apiMethods"; + +import { Module } from "vuex"; +import { RootState } from ".."; + +import { Motive } from "../../../../types"; + +export interface State { + motives: Array; +} + +export const moduleMotive: Module ={ + state: () => ({ + motives: [], + }), + getters: { + getMotives(state) { + return state.motives; + } + }, + mutations: { + setMotives(state, motives) { + state.motives = motives; + } + }, + actions: { + async fetchMotives({ commit }) { + try{ + const results = await fetchResults("/api/1.0/ticket/motive.json") as Motive[]; + commit("setMotives", results); + } + catch (e) { + console.error("Error while fetching motives", e); + } + }, + async createMotive({ commit }, datas: {currentMotiveId: number, motive: Motive}) { + const { currentMotiveId, motive } = datas; + try { + const result = await makeFetch("POST", `/api/1.0/ticket/${currentMotiveId}/motive/set`, motive); + commit("setMotives", result);; + } + catch (e) { + console.error("Error while creating motive", e); + } + } + }, +};
{{ $t('hello', {'name': 'Boris'})}}
{{ ticket.externalRef }}
{{ ticket.currentMotive }}
{{ person.firstName }}
{{ person.lastName }}
{{ ticket_history_line.event_type}}
{{ ticket_history_line.data}}