diff --git a/frontend/src/admin/event/AdminEventService.js b/frontend/src/admin/event/AdminEventService.js deleted file mode 100755 index 586cc9a4..00000000 --- a/frontend/src/admin/event/AdminEventService.js +++ /dev/null @@ -1,45 +0,0 @@ -import { api } from "../../api" - -var module = angular.module("billett.admin") - -module.factory("AdminEvent", ($resource, $http) => { - var r = $resource( - api("event/:id"), - { - id: "@id", - admin: 1, - }, - { - update: { method: "PUT" }, - }, - ) - - r.prototype.setPublish = (state) => { - return $http.patch(api("event/" + this.id), { - is_published: state, - admin: 1, - }) - } - - r.prototype.setSelling = (state) => { - return $http.patch(api("event/" + this.id), { - is_selling: state, - admin: 1, - }) - } - - r.prototype.setTicketgroupsOrder = (groups) => { - var opts = { - admin: 1, - } - - var i = 0 - groups.forEach((group) => { - opts[group.id] = i++ - }) - - return $http.post(api("event/" + this.id + "/ticketgroups_order"), opts) - } - - return r -}) diff --git a/frontend/src/admin/event/admin-event.service.ts b/frontend/src/admin/event/admin-event.service.ts new file mode 100755 index 00000000..e40a1687 --- /dev/null +++ b/frontend/src/admin/event/admin-event.service.ts @@ -0,0 +1,74 @@ +import { HttpClient } from "@angular/common/http" +import { Injectable } from "@angular/core" +import { api } from "../../api" + +export interface AdminEventData { + id: number + [k: string]: any +} + +@Injectable({ + providedIn: "root", +}) +export class AdminEventService { + constructor(private http: HttpClient) {} + + query() { + return this.http.get(api("event"), { + params: { admin: "1" }, + }) + } + + get(id: string) { + return this.http.get( + api(`event/${encodeURIComponent(id)}`), + { + params: { admin: "1" }, + }, + ) + } + + update(id: string, data: AdminEventData) { + return this.http.put( + api(`event/${encodeURIComponent(id)}`), + data, + { params: { admin: "1" } }, + ) + } + + setPublish(id: string, is_published: boolean) { + return this.http.patch( + api(`event/${encodeURIComponent(id)}`), + { + is_published, + admin: 1, + }, + ) + } + + setSelling(id: string, is_selling: boolean) { + return this.http.patch( + api(`event/${encodeURIComponent(id)}`), + { + is_selling, + admin: 1, + }, + ) + } + + setTicketgroupsOrder(id: string, groups) { + let data = { + admin: 1, + } + + let i = 0 + groups.forEach((group) => { + data[group.id] = i++ + }) + + return this.http.post( + api(`event/${encodeURIComponent(id)}/ticketgroups_order`), + data, + ) + } +} diff --git a/frontend/src/admin/eventgroup/AdminEventgroupController.js b/frontend/src/admin/eventgroup/AdminEventgroupController.js deleted file mode 100755 index dbf22e0f..00000000 --- a/frontend/src/admin/eventgroup/AdminEventgroupController.js +++ /dev/null @@ -1,88 +0,0 @@ -import moment from "moment" - -var module = angular.module("billett.admin") - -module.controller( - "AdminEventgroupController", - ( - Page, - $stateParams, - $http, - $scope, - AdminEventgroup, - AdminEvent, - $location, - ) => { - Page.setTitle("Arrangementgruppe") - - var loader = Page.setLoading() - AdminEventgroup.get( - { id: $stateParams["id"] }, - (ret) => { - loader() - - $scope.group = ret - $scope.applyFilter() - - $scope.categories = [] - for (const event of $scope.group.events) { - if ($scope.categories.indexOf(event.category || "") != -1) continue - $scope.categories.push(event.category || "") - } - $scope.categories.sort() - }, - () => { - loader() - Page.set404() - }, - ) - - $scope.filter_sale = "" - $scope.filter_category = "-1" - $scope.filter_hidden = "0" - $scope.applyFilter = () => { - var r = {} - for (const item of $scope.group.events) { - if ( - $scope.filter_sale !== "" && - $scope.filter_sale != !!item.ticketgroups.length - ) - continue - if ( - $scope.filter_category !== "-1" && - $scope.filter_category != (item.category || "") - ) - continue - if ( - $scope.filter_hidden != "" && - $scope.filter_hidden != item.is_admin_hidden - ) - continue - - var k = moment.unix(item.time_start - 3600 * 6).format("YYYY-MM-DD") - r[k] = r[k] || [] - r[k].push(item) - } - - $scope.days = r - } - - $scope.eventTogglePublish = (event) => { - new AdminEvent(event) - .setPublish(!event.is_published) - .then((response) => { - const ret = response.data - event.is_published = ret.is_published - }) - } - - $scope.eventToggleSelling = (event) => { - new AdminEvent(event) - .setSelling(!event.is_selling) - .then((response) => { - const ret = response.data - event.is_selling = ret.is_selling - }) - } - }, -) diff --git a/frontend/src/admin/eventgroup/admin-eventgroup.component.html b/frontend/src/admin/eventgroup/admin-eventgroup.component.html new file mode 100644 index 00000000..94e5593d --- /dev/null +++ b/frontend/src/admin/eventgroup/admin-eventgroup.component.html @@ -0,0 +1,204 @@ + + +@if (group) { +
+ + + + + + +
+ +

+ Arrangementliste + + Nytt arrangement + +

+ + @if (group.events.length == 0) { +
+

Ingen arrangementer eksisterer.

+
+ } @else { +
+
+ + + +
+ + + + + + + + + + + + + + + + @for (item of days | keyvalue; track item.key) { + + + + + @for (event of item.value; track event) { + + + + + + + + + + + + } + + } +
VarighetKategoriStedTittelSalgTilg.OmsattPubBillett-
info
+ {{ + item.value![0].time_start - 21600 + | formatdate: "dddd D. MMMM YYYY" + }} +
+ {{ event.time_start | formatdate: "HH:mm" }} + @if (event.time_end && event.time_end != event.time_start) { + + - {{ event.time_end | formatdate: "HH:mm" }} + + } + {{ event.category }}{{ event.location }} + @if ( + event.max_sales != 0 || + event.ticket_count.totals.valid != 0 + ) { + + {{ event.ticket_count.totals.valid }} + + } + + {{ + event.max_sales == 0 ? "" : event.ticket_count.totals.free + }} + + {{ + event.max_sales == 0 && + event.ticket_count.totals.valid == 0 + ? "" + : (event.ticket_count.totals.sum_price + + event.ticket_count.totals.sum_fee | price) + }} + + + + +
+
+ } +
+} diff --git a/frontend/src/admin/eventgroup/admin-eventgroup.component.ts b/frontend/src/admin/eventgroup/admin-eventgroup.component.ts new file mode 100755 index 00000000..c0d157dc --- /dev/null +++ b/frontend/src/admin/eventgroup/admin-eventgroup.component.ts @@ -0,0 +1,116 @@ +import { CommonModule } from "@angular/common" +import { Component, Input, OnInit } from "@angular/core" +import { FormsModule } from "@angular/forms" +import { RouterLink } from "@angular/router" +import moment from "moment" +import { FormatdatePipe } from "../../common/formatdate.pipe" +import { PagePropertyComponent } from "../../common/page-property.component" +import { PageStatesComponent } from "../../common/page-states.component" +import { PageService } from "../../common/page.service" +import { PricePipe } from "../../common/price.pipe" +import { + handleResourceLoadingStates, + ResourceLoadingState, +} from "../../common/resource-loading" +import { AdminEventService } from "../event/admin-event.service" +import { AdminEventgroupService } from "./admin-eventgroup.service" + +@Component({ + selector: "admin-eventgroup", + standalone: true, + imports: [ + PagePropertyComponent, + RouterLink, + FormsModule, + CommonModule, + FormatdatePipe, + PricePipe, + PageStatesComponent, + ], + templateUrl: "./admin-eventgroup.component.html", +}) +export class AdminEventgroupComponent implements OnInit { + @Input() + id!: string + + pageState = new ResourceLoadingState() + + group: any + filter_sale: any + filter_category: any + filter_hidden: any + categories: any + days?: Record + + constructor( + private adminEventgroupService: AdminEventgroupService, + private adminEventService: AdminEventService, + private pageService: PageService, + ) {} + + ngOnInit(): void { + this.pageService.set("title", "Arrangementgruppe") + + this.adminEventgroupService + .get(this.id) + .pipe(handleResourceLoadingStates(this.pageState)) + .subscribe((data) => { + this.group = data + this.applyFilter() + + this.categories = [] + for (const event of this.group.events) { + if (this.categories.indexOf(event.category || "") != -1) continue + this.categories.push(event.category || "") + } + this.categories.sort() + }) + + this.filter_sale = "" + this.filter_category = "-1" + this.filter_hidden = "0" + } + + applyFilter() { + var r = {} + for (const item of this.group.events) { + if ( + this.filter_sale !== "" && + this.filter_sale != !!item.ticketgroups.length + ) + continue + if ( + this.filter_category !== "-1" && + this.filter_category != (item.category || "") + ) + continue + if ( + this.filter_hidden != "" && + this.filter_hidden != item.is_admin_hidden + ) + continue + + var k = moment.unix(item.time_start - 3600 * 6).format("YYYY-MM-DD") + r[k] = r[k] || [] + r[k].push(item) + } + + this.days = r + } + + eventTogglePublish(event) { + this.adminEventService + .setPublish(event.id, !event.is_published) + .subscribe((data) => { + event.is_published = data.is_published + }) + } + + eventToggleSelling(event) { + this.adminEventService + .setSelling(event.id, !event.is_selling) + .subscribe((data) => { + event.is_selling = data.is_selling + }) + } +} diff --git a/frontend/src/admin/eventgroup/index.html b/frontend/src/admin/eventgroup/index.html deleted file mode 100644 index 940accd8..00000000 --- a/frontend/src/admin/eventgroup/index.html +++ /dev/null @@ -1,182 +0,0 @@ -
- - - - - - -
- -

- Arrangementliste - - Nytt arrangement - -

- -
-

Ingen arrangementer eksisterer.

-
- -
-
- - - -
- - - - - - - - - - - - - - - - @for ((day, events) in days; track (day, events) in days) { - - - - - @for (event of events; track event) { - - - - - - - - - - - - } - - } -
VarighetKategoriStedTittelSalgTilg.OmsattPubBillett-
info
- {{ - events[0].time_start - 21600 | formatdate: "dddd D. MMMM YYYY" - }} -
- {{ event.time_start | formatdate: "HH:mm" }} - - - {{ event.time_end | formatdate: "HH:mm" }} - - {{ event.category }}{{ event.location }} - - {{::event.ticket_count.totals.valid}} - - - {{ event.max_sales == 0 ? "" : event.ticket_count.totals.free }} - - {{event.max_sales == 0 && event.ticket_count.totals.valid == 0 ? '' - : - (event.ticket_count.totals.sum_price+event.ticket_count.totals.sum_fee|price)}} - - - - -
-
-
diff --git a/frontend/src/admin/eventgroup/routes.ts b/frontend/src/admin/eventgroup/routes.ts index f470a019..d16ec5ad 100755 --- a/frontend/src/admin/eventgroup/routes.ts +++ b/frontend/src/admin/eventgroup/routes.ts @@ -1,6 +1,7 @@ import { Routes } from "@angular/router" import { requireAdmin } from "../../auth/require-admin" import { TodoComponent } from "../todo.component" +import { AdminEventgroupComponent } from "./admin-eventgroup.component" export const routes: Routes = [ { @@ -19,9 +20,7 @@ export const routes: Routes = [ }, { path: "a/eventgroup/:id", - // index.html - // component: AdminEventgroupComponent, - component: TodoComponent, + component: AdminEventgroupComponent, canActivate: [requireAdmin], }, { diff --git a/frontend/src/admin/order/routes.ts b/frontend/src/admin/order/routes.ts index 275ce44a..9e3aeafc 100755 --- a/frontend/src/admin/order/routes.ts +++ b/frontend/src/admin/order/routes.ts @@ -18,7 +18,8 @@ export const routes: Routes = [ canActivate: [requireAdmin], }, { - path: "a/orders?eventgroup_id", + path: "a/orders", + // ?eventgroup_id // index.html // component: AdminOrderListComponent, component: TodoComponent, diff --git a/frontend/tsconfig.json b/frontend/tsconfig.json index 3fa4a8b2..1be54b2b 100644 --- a/frontend/tsconfig.json +++ b/frontend/tsconfig.json @@ -7,7 +7,7 @@ "strict": true, "noImplicitOverride": true, "noImplicitAny": false, - "noPropertyAccessFromIndexSignature": true, + "noPropertyAccessFromIndexSignature": false, "noImplicitReturns": true, "noFallthroughCasesInSwitch": true, "skipLibCheck": true,