2021-05-19 13:40:29 +02:00
|
|
|
import {Component, OnDestroy, OnInit, ViewChild} from "@angular/core";
|
|
|
|
import {CommunityInfo} from "../../../openaireLibrary/connect/community/communityInfo";
|
|
|
|
import {EnvProperties} from "../../../openaireLibrary/utils/properties/env-properties";
|
|
|
|
import {properties} from "../../../../environments/environment";
|
|
|
|
import {EditCommunityComponent} from "./edit-community/edit-community.component";
|
|
|
|
import {CommunityService} from "../../../openaireLibrary/connect/community/community.service";
|
|
|
|
import {Title} from "@angular/platform-browser";
|
|
|
|
import {Subscription} from "rxjs";
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'community-profile',
|
|
|
|
template: `
|
2022-06-29 12:19:29 +02:00
|
|
|
<div page-content (stickyEmitter)="stickyPageHeader = $event">
|
2021-05-19 13:40:29 +02:00
|
|
|
<div header>
|
2022-06-29 12:19:29 +02:00
|
|
|
<div class="uk-flex uk-flex-middle uk-margin-top info" [class.uk-active]="stickyPageHeader">
|
|
|
|
<div>
|
2022-06-30 12:41:36 +02:00
|
|
|
<div class="uk-margin-remove uk-text-background uk-text-bold uk-h6">Admin Dashboard - Manage Community
|
|
|
|
Profile
|
|
|
|
</div>
|
2022-06-29 12:19:29 +02:00
|
|
|
<h1 class="uk-h4 uk-margin-remove">{{community.shortTitle}}</h1>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-05-19 13:40:29 +02:00
|
|
|
<community-info tab="profile"></community-info>
|
|
|
|
</div>
|
|
|
|
<div inner>
|
2022-06-29 12:19:29 +02:00
|
|
|
<div class="uk-container">
|
2022-06-30 12:41:36 +02:00
|
|
|
<div class="uk-flex uk-flex-right@m uk-flex-center uk-margin-top">
|
2022-06-29 12:19:29 +02:00
|
|
|
<div class="uk-width-auto uk-text-right@m uk-text-center">
|
|
|
|
<button class="uk-button uk-button-default uk-margin-right"
|
|
|
|
(click)="reset()" [class.uk-disabled]="loading || !editCommunityComponent.dirty"
|
2021-05-19 13:40:29 +02:00
|
|
|
[disabled]="loading || !editCommunityComponent.dirty">Reset
|
|
|
|
</button>
|
2022-06-29 12:19:29 +02:00
|
|
|
<button class="uk-button uk-button-primary"
|
|
|
|
[class.uk-disabled]="loading || editCommunityComponent.disabled"
|
|
|
|
(click)="save()" [disabled]="loading || editCommunityComponent.disabled">Save
|
2021-05-19 13:40:29 +02:00
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-06-29 12:19:29 +02:00
|
|
|
<div class="uk-position-relative" style="min-height: 60vh">
|
2022-06-30 12:41:36 +02:00
|
|
|
<div [class.hidden]="loading" class="uk-section uk-section-small">
|
2022-06-29 12:19:29 +02:00
|
|
|
<edit-community #editCommunityComponent></edit-community>
|
|
|
|
</div>
|
|
|
|
<div *ngIf="loading" class="uk-position-center">
|
|
|
|
<loading></loading>
|
|
|
|
</div>
|
2021-05-19 13:40:29 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
`
|
|
|
|
})
|
|
|
|
export class ProfileComponent implements OnInit, OnDestroy {
|
|
|
|
|
|
|
|
public community: CommunityInfo;
|
|
|
|
public properties: EnvProperties = properties;
|
|
|
|
public loading: boolean = false;
|
|
|
|
private subscriptions: any[] = [];
|
2022-06-30 12:41:36 +02:00
|
|
|
@ViewChild('editCommunityComponent', {static: true}) editCommunityComponent: EditCommunityComponent;
|
|
|
|
|
2022-06-29 12:19:29 +02:00
|
|
|
public stickyPageHeader: boolean = false;
|
2022-06-30 12:41:36 +02:00
|
|
|
|
2021-05-19 13:40:29 +02:00
|
|
|
constructor(private communityService: CommunityService,
|
|
|
|
private title: Title) {
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
this.loading = true;
|
|
|
|
this.subscriptions.push(this.communityService.getCommunityAsObservable().subscribe(community => {
|
|
|
|
this.community = community;
|
|
|
|
if (this.community) {
|
|
|
|
this.title.setTitle(this.community.communityId.toUpperCase() + " | Profile");
|
|
|
|
setTimeout(() => {
|
|
|
|
this.reset();
|
|
|
|
this.loading = false;
|
|
|
|
}, 200);
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
public reset() {
|
|
|
|
this.editCommunityComponent.init(this.community);
|
|
|
|
}
|
|
|
|
|
|
|
|
public save() {
|
|
|
|
this.loading = true;
|
|
|
|
this.editCommunityComponent.save((community) => {
|
|
|
|
this.community = community;
|
|
|
|
this.reset();
|
|
|
|
this.loading = false;
|
|
|
|
}, (error) => {
|
|
|
|
this.loading = false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnDestroy() {
|
|
|
|
this.subscriptions.forEach(subscription => {
|
|
|
|
if (subscription instanceof Subscription) {
|
|
|
|
subscription.unsubscribe();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|