Skip to content

Commit

Permalink
Migrate admin daytheme
Browse files Browse the repository at this point in the history
A lot of this was unused/not fully implemented.
  • Loading branch information
henrist committed Jul 13, 2024
1 parent 29f1cf2 commit fd99a4e
Show file tree
Hide file tree
Showing 13 changed files with 143 additions and 500 deletions.
30 changes: 0 additions & 30 deletions frontend/src/admin/daytheme/AdminDaythemeController.js

This file was deleted.

82 changes: 0 additions & 82 deletions frontend/src/admin/daytheme/AdminDaythemeEditNewController.js

This file was deleted.

18 changes: 0 additions & 18 deletions frontend/src/admin/daytheme/AdminDaythemeService.js

This file was deleted.

40 changes: 40 additions & 0 deletions frontend/src/admin/daytheme/admin-daytheme-create.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<page-states [state]="pageState"></page-states>

@if (eventgroup) {
<div class="page-header">
<h1>Ny temadag for {{ eventgroup.title }}</h1>
</div>

<form (ngSubmit)="storeDaytheme()" class="form-horizontal" autocomplete="off">
<h3>Grunnleggende informasjon</h3>
<div class="form-group">
<label for="title" class="col-sm-3 control-label">Tittel</label>
<div class="col-sm-9 col-md-6">
<input
type="text"
name="title"
class="form-control"
[(ngModel)]="form.title"
required
autofocus
/>
</div>
<div class="col-sm-4 col-md-3">
<input
type="datetime"
name="date"
class="form-control"
[(ngModel)]="form.date"
placeholder="YYYY-MM-DD"
/>
</div>
</div>

<div class="form-group">
<div class="col-sm-9 col-md-6 col-sm-offset-3">
<input type="submit" value="Opprett" class="btn btn-primary" />
<a routerLink="/a/eventgroup/{{ eventgroupId }}">Avbryt</a>
</div>
</div>
</form>
}
77 changes: 77 additions & 0 deletions frontend/src/admin/daytheme/admin-daytheme-create.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { Component, Input, OnInit } from "@angular/core"
import { FormsModule } from "@angular/forms"
import { Router, RouterLink } from "@angular/router"
import moment from "moment"
import { catchError, of } from "rxjs"
import { PageStatesComponent } from "../../common/page-states.component"
import { PageService } from "../../common/page.service"
import {
handleResourceLoadingStates,
ResourceLoadingState,
} from "../../common/resource-loading"
import {
AdminEventgroupData,
AdminEventgroupService,
} from "../eventgroup/admin-eventgroup.service"
import { AdminDaythemeService } from "./admin-daytheme.service"

@Component({
selector: "admin-daytheme",
standalone: true,
imports: [PageStatesComponent, RouterLink, FormsModule],
templateUrl: "./admin-daytheme-create.component.html",
})
export class AdminDaythemeCreateComponent implements OnInit {
@Input()
eventgroupId!: string

pageState = new ResourceLoadingState()
eventgroup?: AdminEventgroupData
form = {
title: "",
date: "",
}

constructor(
private adminDaythemeService: AdminDaythemeService,
private adminEventgroupService: AdminEventgroupService,
private pageService: PageService,
private router: Router,
) {}

ngOnInit(): void {
this.pageService.set("title", "Ny temadag")
this.adminEventgroupService
.get(this.eventgroupId)
.pipe(handleResourceLoadingStates(this.pageState))
.subscribe((data) => {
this.eventgroup = data
})
}

storeDaytheme() {
if (!this.form || !this.form.title || !this.form.date) return

const date = moment(this.form.date, "YYYY-MM-DD").unix()
if (!date) {
alert("Ugyldig dato")
return
}

this.adminDaythemeService
.create({
eventgroup_id: this.eventgroup!.id,
date,
title: this.form.title,
})
.pipe(
catchError((err) => {
alert(err)
return of()
}),
)
.subscribe(() => {
this.router.navigateByUrl(`/a/eventgroup/${this.eventgroupId}`)
})
}
}
22 changes: 22 additions & 0 deletions frontend/src/admin/daytheme/admin-daytheme.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { HttpClient } from "@angular/common/http"
import { Injectable } from "@angular/core"
import { api } from "../../api"

export interface AdminDaythemeCreateData {
eventgroup_id: number
title?: string
date?: number
}

@Injectable({
providedIn: "root",
})
export class AdminDaythemeService {
constructor(private http: HttpClient) {}

create(data: AdminDaythemeCreateData) {
return this.http.post<AdminDaythemeCreateData>(api("daytheme"), data, {
params: { admin: "1" },
})
}
}
105 changes: 0 additions & 105 deletions frontend/src/admin/daytheme/daytheme.scss

This file was deleted.

Loading

0 comments on commit fd99a4e

Please sign in to comment.