-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cf54ec5
commit 7bc7fe3
Showing
13 changed files
with
279 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/app/endorsements/pages/edit-endorsement-reasons/edit-endorsement-reasons.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<app-loader *ngIf="loading else content"></app-loader> | ||
|
||
<ng-template #content> | ||
<div class="col-md-12"> | ||
<div class="card"> | ||
<div class="card-body"> | ||
<p>Endorsing means that you approve of an instance. For more information visit the <a routerLink="/glossary">Glossary</a>.</p> | ||
<p><strong>You can do this only if your instance is guaranteed by some other instance.</strong></p> | ||
<form [formGroup]="form" (submit)="updateReasons()"> | ||
<div class="form-group"> | ||
<label for="inputInstance">Instance to endorse</label> | ||
<input class="form-control" type="text" id="inputInstance" formControlName="instance" /> | ||
</div> | ||
<div class="form-group"> | ||
<label for="inputReason">Reasons</label> | ||
<select formControlName="reasons" id="inputReason" multiple tom-select [maxItems]="null" [create]="true"> | ||
<option *ngFor="let option of availableReasons" [value]="option">{{option}}</option> | ||
</select> | ||
</div> | ||
<button type="submit" class="btn btn-primary">Update</button> | ||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
</ng-template> |
3 changes: 3 additions & 0 deletions
3
src/app/endorsements/pages/edit-endorsement-reasons/edit-endorsement-reasons.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
:host { | ||
min-width: 100%; | ||
} |
104 changes: 104 additions & 0 deletions
104
src/app/endorsements/pages/edit-endorsement-reasons/edit-endorsement-reasons.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import {Component, OnInit} from '@angular/core'; | ||
import {FormControl, FormGroup, Validators} from "@angular/forms"; | ||
import {TitleService} from "../../../services/title.service"; | ||
import {MessageService} from "../../../services/message.service"; | ||
import {FediseerApiService} from "../../../services/fediseer-api.service"; | ||
import {ActivatedRoute, Router} from "@angular/router"; | ||
import {AuthenticationManagerService} from "../../../services/authentication-manager.service"; | ||
import {ApiResponseHelperService} from "../../../services/api-response-helper.service"; | ||
import {toPromise} from "../../../types/resolvable"; | ||
import {map} from "rxjs"; | ||
import {NormalizedInstanceDetailResponse} from "../../../response/normalized-instance-detail.response"; | ||
|
||
@Component({ | ||
selector: 'app-edit-endorsement-reasons', | ||
templateUrl: './edit-endorsement-reasons.component.html', | ||
styleUrls: ['./edit-endorsement-reasons.component.scss'] | ||
}) | ||
export class EditEndorsementReasonsComponent implements OnInit { | ||
public form = new FormGroup({ | ||
instance: new FormControl<string>({value: '', disabled: true}, [Validators.required]), | ||
reasons: new FormControl<string[]>([]), | ||
}); | ||
public loading: boolean = true; | ||
public availableReasons: string[] = []; | ||
|
||
constructor( | ||
private readonly titleService: TitleService, | ||
private readonly messageService: MessageService, | ||
private readonly api: FediseerApiService, | ||
private readonly router: Router, | ||
private readonly activatedRoute: ActivatedRoute, | ||
private readonly authManager: AuthenticationManagerService, | ||
private readonly apiResponseHelper: ApiResponseHelperService, | ||
) { | ||
} | ||
|
||
public async ngOnInit(): Promise<void> { | ||
this.titleService.title = 'Update endorsement reasons'; | ||
|
||
this.activatedRoute.params.subscribe(async params => { | ||
const targetInstance = params['instance'] as string; | ||
let availableReasons = await toPromise(this.api.usedEndorsementReasons); | ||
if (availableReasons === null) { | ||
this.messageService.createWarning(`Couldn't get list of reasons that were used previously, autocompletion won't work.`); | ||
availableReasons = []; | ||
} | ||
this.availableReasons = availableReasons; | ||
|
||
const existing = await toPromise( | ||
this.api.getEndorsementsByInstance([this.authManager.currentInstanceSnapshot.name]).pipe( | ||
map(response => { | ||
if (this.apiResponseHelper.handleErrors([response])) { | ||
return null; | ||
} | ||
|
||
const instance = response.successResponse!.instances.filter( | ||
instance => instance.domain === targetInstance, | ||
); | ||
if (!instance.length) { | ||
this.messageService.createError(`Couldn't find this instance amongst your endorsements. Are you sure you've endorsed it?`); | ||
return null; | ||
} | ||
|
||
return instance[0]; | ||
}), | ||
), | ||
); | ||
|
||
if (existing === null) { | ||
this.loading = false; | ||
return; | ||
} | ||
|
||
this.form.patchValue({ | ||
instance: existing.domain, | ||
reasons: NormalizedInstanceDetailResponse.fromInstanceDetail(existing).unmergedEndorsementReasons, | ||
}); | ||
this.loading = false; | ||
}); | ||
} | ||
|
||
public async updateReasons(): Promise<void> { | ||
if (!this.form.valid) { | ||
this.messageService.createError("The form is not valid, please make sure all fields are filled correctly."); | ||
return; | ||
} | ||
|
||
this.loading = true; | ||
this.api.updateEndorsement( | ||
this.form.controls.instance.value!, | ||
this.form.controls.reasons.value ? this.form.controls.reasons.value!.join(',') : null, | ||
).subscribe(response => { | ||
if (this.apiResponseHelper.handleErrors([response])) { | ||
this.loading = false; | ||
return; | ||
} | ||
|
||
this.loading = false; | ||
this.router.navigateByUrl('/endorsements/my').then(() => { | ||
this.messageService.createSuccess(`${this.form.controls.instance.value} was successfully updated!`); | ||
}); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.