From 0ab002b5a488acf42b51a84a8b2489734ddf9469 Mon Sep 17 00:00:00 2001 From: Adrian Matei Date: Mon, 4 Sep 2023 10:34:06 +0200 Subject: [PATCH] feat - add "clone" bookmark functionality --- .../clone-bookmark.component.html | 5 +++ .../clone-bookmark.component.scss | 35 +++++++++++++++++++ .../clone-bookmark.component.ts | 18 ++++++++++ .../my-bookmarks-routing.module.ts | 5 +++ .../app/my-bookmarks/my-bookmarks.module.ts | 2 ++ .../save-bookmark-form.component.ts | 15 ++++++-- .../save-note-form/note-editor.component.ts | 2 ++ .../bookmark-list-element.component.html | 9 +++++ .../bookmark-list-element.component.ts | 5 +++ package.json | 2 +- 10 files changed, 94 insertions(+), 4 deletions(-) create mode 100644 apps/codever-ui/src/app/my-bookmarks/clone-bookmark/clone-bookmark.component.html create mode 100644 apps/codever-ui/src/app/my-bookmarks/clone-bookmark/clone-bookmark.component.scss create mode 100644 apps/codever-ui/src/app/my-bookmarks/clone-bookmark/clone-bookmark.component.ts diff --git a/apps/codever-ui/src/app/my-bookmarks/clone-bookmark/clone-bookmark.component.html b/apps/codever-ui/src/app/my-bookmarks/clone-bookmark/clone-bookmark.component.html new file mode 100644 index 00000000..fd4360ba --- /dev/null +++ b/apps/codever-ui/src/app/my-bookmarks/clone-bookmark/clone-bookmark.component.html @@ -0,0 +1,5 @@ + diff --git a/apps/codever-ui/src/app/my-bookmarks/clone-bookmark/clone-bookmark.component.scss b/apps/codever-ui/src/app/my-bookmarks/clone-bookmark/clone-bookmark.component.scss new file mode 100644 index 00000000..622e992a --- /dev/null +++ b/apps/codever-ui/src/app/my-bookmarks/clone-bookmark/clone-bookmark.component.scss @@ -0,0 +1,35 @@ +label { + display: inline-block; + margin: 0.5em 0; + color: #607d8b; + font-weight: bold; +} +input { + height: 2em; + font-size: 1em; + padding-left: 0.4em; +} + +input[type='checkbox'], +input[type='radio'] { + vertical-align: middle; + position: relative; + bottom: 1px; +} + +#shared_label { + width: 100%; +} + +mat-chip { + max-width: 200px; +} + +.demo-chip-list { + width: 100%; +} + +.markdown-link { + font-weight: normal; + margin-left: 0.15rem; +} diff --git a/apps/codever-ui/src/app/my-bookmarks/clone-bookmark/clone-bookmark.component.ts b/apps/codever-ui/src/app/my-bookmarks/clone-bookmark/clone-bookmark.component.ts new file mode 100644 index 00000000..5de8437b --- /dev/null +++ b/apps/codever-ui/src/app/my-bookmarks/clone-bookmark/clone-bookmark.component.ts @@ -0,0 +1,18 @@ +import { Component, OnInit } from '@angular/core'; +import { Bookmark } from '../../core/model/bookmark'; +import { Observable, of } from 'rxjs'; + +@Component({ + selector: 'app-clone-bookmark', + templateUrl: './clone-bookmark.component.html', + styleUrls: ['./clone-bookmark.component.scss'], +}) +export class CloneBookmarkComponent implements OnInit { + bookmark$: Observable; + + constructor() {} + + ngOnInit(): void { + this.bookmark$ = of(window.history.state.bookmark); + } +} diff --git a/apps/codever-ui/src/app/my-bookmarks/my-bookmarks-routing.module.ts b/apps/codever-ui/src/app/my-bookmarks/my-bookmarks-routing.module.ts index 21d21085..c765db83 100644 --- a/apps/codever-ui/src/app/my-bookmarks/my-bookmarks-routing.module.ts +++ b/apps/codever-ui/src/app/my-bookmarks/my-bookmarks-routing.module.ts @@ -6,6 +6,7 @@ import { UpdatePersonalBookmarkComponent } from './update/update-personal-bookma import { CreatePersonalBookmarkComponent } from './create/create-personal-bookmark.component'; import { CopyToMineBookmarkComponent } from './copy-to-mine/copy-to-mine-bookmark.component'; import { BookmarkDetailsComponent } from './bookmark-details/bookmark-details.component'; +import { CloneBookmarkComponent } from './clone-bookmark/clone-bookmark.component'; const myBookmarksRoutes: Routes = [ { @@ -21,6 +22,10 @@ const myBookmarksRoutes: Routes = [ path: ':id/copy-to-mine', component: CopyToMineBookmarkComponent, }, + { + path: ':id/clone', + component: CloneBookmarkComponent, + }, { path: ':id/details', component: BookmarkDetailsComponent, diff --git a/apps/codever-ui/src/app/my-bookmarks/my-bookmarks.module.ts b/apps/codever-ui/src/app/my-bookmarks/my-bookmarks.module.ts index 905901c5..c6e381b6 100644 --- a/apps/codever-ui/src/app/my-bookmarks/my-bookmarks.module.ts +++ b/apps/codever-ui/src/app/my-bookmarks/my-bookmarks.module.ts @@ -18,12 +18,14 @@ import { MatIconModule } from '@angular/material/icon'; import { MatAutocompleteModule } from '@angular/material/autocomplete'; import { MatTabsModule } from '@angular/material/tabs'; import { MatDialogModule } from '@angular/material/dialog'; +import { CloneBookmarkComponent } from './clone-bookmark/clone-bookmark.component'; @NgModule({ declarations: [ CreatePersonalBookmarkComponent, UpdatePersonalBookmarkComponent, CopyToMineBookmarkComponent, + CloneBookmarkComponent, MyBookmarksEntryPointComponent, PublicBookmarkPresentDialogComponent, SaveBookmarkFormComponent, diff --git a/apps/codever-ui/src/app/my-bookmarks/save-bookmark-form/save-bookmark-form.component.ts b/apps/codever-ui/src/app/my-bookmarks/save-bookmark-form/save-bookmark-form.component.ts index e8de87e9..81dd96e7 100644 --- a/apps/codever-ui/src/app/my-bookmarks/save-bookmark-form/save-bookmark-form.component.ts +++ b/apps/codever-ui/src/app/my-bookmarks/save-bookmark-form/save-bookmark-form.component.ts @@ -109,6 +109,9 @@ export class SaveBookmarkFormComponent implements OnInit { @Input() copyToMine = false; + @Input() + cloneBookmark = false; + bookmark: Bookmark; constructor( @@ -159,7 +162,7 @@ export class SaveBookmarkFormComponent implements OnInit { ngOnInit(): void { this.buildForm(); - if (this.isUpdate || this.copyToMine) { + if (this.isUpdate || this.copyToMine || this.cloneBookmark) { this.bookmark$.subscribe((bookmark) => { this.bookmark = bookmark; this.makePublic = this.bookmark.public; @@ -169,6 +172,12 @@ export class SaveBookmarkFormComponent implements OnInit { this.bookmark.public = false; this.verifyExistenceInPersonalBookmarks(bookmark.location); } + if (this.cloneBookmark) { + this.bookmark._id = null; + this.makePublic = false; + this.bookmark.public = false; + this.bookmark.location = 'CHANGE ME'; + } this.bookmarkForm.patchValue(this.bookmark); this.bookmarkForm .get('publishedOn') @@ -210,7 +219,7 @@ export class SaveBookmarkFormComponent implements OnInit { } private onChanges() { - const isNewBookmark = !this.isUpdate && !this.copyToMine; + const isNewBookmark = !this.isUpdate && !this.copyToMine && !this.cloneBookmark if (isNewBookmark) { this.bookmarkForm .get('location') @@ -404,7 +413,7 @@ export class SaveBookmarkFormComponent implements OnInit { saveBookmark(bookmark: Bookmark) { if (this.isUpdate) { this.updateBookmark(bookmark); - } else if (this.copyToMine) { + } else if (this.copyToMine || this.cloneBookmark) { this.copyBookmarkToMine(bookmark); } else { this.createBookmark(bookmark); diff --git a/apps/codever-ui/src/app/my-notes/save-note-form/note-editor.component.ts b/apps/codever-ui/src/app/my-notes/save-note-form/note-editor.component.ts index 6770cb27..143bf944 100644 --- a/apps/codever-ui/src/app/my-notes/save-note-form/note-editor.component.ts +++ b/apps/codever-ui/src/app/my-notes/save-note-form/note-editor.component.ts @@ -1,5 +1,6 @@ import { map, startWith, switchMap, takeUntil } from 'rxjs/operators'; import { + ChangeDetectionStrategy, Component, ElementRef, Input, @@ -55,6 +56,7 @@ import { DeleteNotificationService } from '../../core/notifications/delete-notif @Component({ selector: 'app-note-editor', templateUrl: './note-editor.component.html', + changeDetection: ChangeDetectionStrategy.OnPush, }) export class NoteEditorComponent implements OnInit, OnDestroy, OnChanges { noteForm: UntypedFormGroup; diff --git a/apps/codever-ui/src/app/shared/bookmark-list-element/bookmark-list-element.component.html b/apps/codever-ui/src/app/shared/bookmark-list-element/bookmark-list-element.component.html index e046021e..5a5d179c 100644 --- a/apps/codever-ui/src/app/shared/bookmark-list-element/bookmark-list-element.component.html +++ b/apps/codever-ui/src/app/shared/bookmark-list-element/bookmark-list-element.component.html @@ -334,6 +334,15 @@
> Copy to mine +