Skip to content

Commit

Permalink
resources: smoother edit title (fixes #7728) (#7731)
Browse files Browse the repository at this point in the history
Co-authored-by: mutugiii <[email protected]>
Co-authored-by: dogi <[email protected]>
  • Loading branch information
3 people authored Nov 15, 2024
1 parent eaec458 commit 7dc950d
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "planet",
"license": "AGPL-3.0",
"version": "0.15.46",
"version": "0.15.47",
"myplanet": {
"latest": "v0.20.97",
"min": "v0.19.97"
Expand Down
4 changes: 2 additions & 2 deletions src/app/courses/add-courses/courses-add.component.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<mat-toolbar>
<a mat-icon-button (click)="navigateBack()"><mat-icon>arrow_back</mat-icon></a>
<span i18n>Add Course</span>
<span i18n>{{ pageType }} Course</span>
</mat-toolbar>

<div class="space-container">
<mat-toolbar class="primary-color font-size-1">
<span i18n>{this.pageType, select, Add new {Add new} Update {Update}} Course</span>
<span i18n>{this.pageType, select, Add {Add} Edit {Edit}} Course</span>
</mat-toolbar>
<div class="view-container view-full-height">
<div class="form-container">
Expand Down
10 changes: 6 additions & 4 deletions src/app/courses/add-courses/courses-add.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class CoursesAddComponent implements OnInit, OnDestroy {
courseForm: FormGroup;
documentInfo = { '_rev': undefined, '_id': undefined };
courseId = this.route.snapshot.paramMap.get('id') || undefined;
pageType = 'Add new';
pageType: string | null = null;
tags = this.fb.control([]);
private onDestroy$ = new Subject<void>();
private isDestroyed = false;
Expand Down Expand Up @@ -107,7 +107,9 @@ export class CoursesAddComponent implements OnInit, OnDestroy {
]).subscribe(([ draft, saved, tags ]: [ any, any, any[] ]) => {
if (saved.error !== 'not_found') {
this.setDocumentInfo(saved);
this.pageType = 'Update';
this.pageType = 'Edit';
} else {
this.pageType = 'Add';
}
const doc = draft === undefined ? saved : draft;
this.setInitialTags(tags, this.documentInfo, draft);
Expand Down Expand Up @@ -197,7 +199,7 @@ export class CoursesAddComponent implements OnInit, OnDestroy {
)
])
)).subscribe(([ courseRes, tagsRes ]) => {
const message = courseInfo.courseTitle + (this.pageType === 'Update' ? $localize` Updated Successfully` : $localize` Added`);
const message = courseInfo.courseTitle + (this.pageType === 'Edit' ? $localize` Updated Successfully` : $localize` Added`);
this.courseChangeComplete(message, courseRes, shouldNavigate);
}, (err) => {
// Connect to an error display component to show user that an error has occurred
Expand Down Expand Up @@ -229,7 +231,7 @@ export class CoursesAddComponent implements OnInit, OnDestroy {
this.setDocumentInfo(response.doc);
this.stateService.getCouchState('tags', 'local').subscribe((tags) => this.setInitialTags(tags, this.documentInfo));
this.coursesService.course = { ...this.documentInfo };
if (this.pageType === 'Add new') {
if (this.pageType === 'Add') {
this.router.navigate([ '../update/', this.courseId ], { relativeTo: this.route, replaceUrl: true });
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/resources/resources-add.component.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<mat-toolbar *ngIf="!isDialog">
<a mat-icon-button routerLink="/resources"><mat-icon>arrow_back</mat-icon></a>
<span i18n>Add Resource</span>
<span *ngIf="pageType" i18n>{{ pageType }} Resource</span>
</mat-toolbar>

<div [ngClass]="{'space-container':!isDialog}">
<mat-toolbar class="primary-color font-size-1" i18n>{this.pageType, select, Add new {Add new} Update {Update}} Resource</mat-toolbar>
<mat-toolbar class="primary-color font-size-1" i18n>{this.pageType, select, Add {Add} Edit {Edit}} Resource</mat-toolbar>
<div class="view-container view-full-height">
<div>
<form class="form-spacing" [formGroup]="resourceForm" novalidate>
Expand Down
8 changes: 5 additions & 3 deletions src/app/resources/resources-add.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class ResourcesAddComponent implements OnInit {
resourceForm: FormGroup;
readonly dbName = 'resources'; // make database name a constant
userDetail: any = {};
pageType = 'Add new';
pageType: string | null = null;
disableDownload = true;
disableDelete = true;
resourceFilename = '';
Expand Down Expand Up @@ -90,12 +90,14 @@ export class ResourcesAddComponent implements OnInit {
if (!this.isDialog && this.route.snapshot.url[0].path === 'update') {
this.resourcesService.resourcesListener(false).pipe(first())
.subscribe((resources: any[]) => {
this.pageType = 'Update';
this.pageType = 'Edit';
const resource = resources.find(r => r._id === this.route.snapshot.paramMap.get('id'));
this.existingResource = resource;
}, (error) => {
console.log(error);
});
} else {
this.pageType = 'Add';
}

this.filteredZipFiles = this.resourceForm.controls.openWhichFile.valueChanges
Expand Down Expand Up @@ -182,7 +184,7 @@ export class ResourcesAddComponent implements OnInit {
// Start with empty object so this.resourceForm.value does not change
const newResource = Object.assign({}, existingData, this.resourceForm.value, resource);
const message = newResource.title +
(this.pageType === 'Update' || this.existingResource.doc ? $localize` Updated Successfully` : $localize` Added`);
(this.pageType === 'Edit' || this.existingResource.doc ? $localize` Updated Successfully` : $localize` Added`);
const currentTags = (this.existingResource.tags || []).map(tag => tag._id);
if (JSON.stringify(existingData) !== JSON.stringify(newResource) || !deepEqual(currentTags, this.tags.value)) {
this.updateResource(newResource, file).subscribe(
Expand Down

0 comments on commit 7dc950d

Please sign in to comment.