matrix-dimension/web/app/admin/terms/terms.component.ts

48 lines
1.5 KiB
TypeScript
Raw Normal View History

2019-07-01 01:05:33 -04:00
import { Component, OnInit } from "@angular/core";
import { ToasterService } from "angular2-toaster";
import { FE_TermsEditable } from "../../shared/models/terms";
import { AdminTermsApiService } from "../../shared/services/admin/admin-terms-api.service";
import { ActivatedRoute, Router } from "@angular/router";
import { TranslateService } from "@ngx-translate/core";
2019-07-01 01:05:33 -04:00
@Component({
templateUrl: "./terms.component.html",
styleUrls: ["./terms.component.scss"],
})
export class AdminTermsComponent implements OnInit {
2019-07-06 17:19:27 -04:00
// TODO: "New draft" per policy button
// TODO: Delete button
2019-07-01 01:05:33 -04:00
public isLoading = true;
public policies: FE_TermsEditable[];
constructor(private adminTerms: AdminTermsApiService,
2021-09-01 19:01:01 -04:00
private toaster: ToasterService,
private router: Router,
private activatedRoute: ActivatedRoute,
public translate: TranslateService) {
this.translate = translate;
2019-07-01 01:05:33 -04:00
}
public ngOnInit() {
this.adminTerms.getAllPolicies().then(policies => {
this.policies = [
...policies.filter(p => p.version === "draft"),
...policies.filter(p => p.version !== "draft"),
];
2019-07-01 01:05:33 -04:00
this.isLoading = false;
}).catch(err => {
console.error(err);
2021-09-01 19:01:01 -04:00
this.translate.get('Failed to load policies').subscribe((res: string) => {
this.toaster.pop("error", res);
});
2019-07-01 01:05:33 -04:00
});
}
public createPolicy() {
this.router.navigate(["new"], {relativeTo: this.activatedRoute});
}
2019-07-01 01:05:33 -04:00
}