diff --git a/frontend/src/app/app.component.html b/frontend/src/app/app.component.html index 6d06830..872112c 100644 --- a/frontend/src/app/app.component.html +++ b/frontend/src/app/app.component.html @@ -14,4 +14,5 @@ \ No newline at end of file + + \ No newline at end of file diff --git a/frontend/src/app/shared/components/context-menu/context-menu.component.css b/frontend/src/app/shared/components/context-menu/context-menu.component.css new file mode 100644 index 0000000..7a554e9 --- /dev/null +++ b/frontend/src/app/shared/components/context-menu/context-menu.component.css @@ -0,0 +1,23 @@ +.context-menu { + position: absolute; + background-color: #fff; + border: 1px solid #ccc; + box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2); + z-index: 1000; + display: block; +} + +.context-menu ul { + list-style: none; + padding: 0; + margin: 0; +} + +.context-menu li { + padding: 8px 12px; + cursor: pointer; +} + +.context-menu li:hover { + background-color: #f0f0f0; +} \ No newline at end of file diff --git a/frontend/src/app/shared/components/context-menu/context-menu.component.html b/frontend/src/app/shared/components/context-menu/context-menu.component.html new file mode 100644 index 0000000..6bf5414 --- /dev/null +++ b/frontend/src/app/shared/components/context-menu/context-menu.component.html @@ -0,0 +1,7 @@ +
+ +
\ No newline at end of file diff --git a/frontend/src/app/shared/components/context-menu/context-menu.component.spec.ts b/frontend/src/app/shared/components/context-menu/context-menu.component.spec.ts new file mode 100644 index 0000000..61878c9 --- /dev/null +++ b/frontend/src/app/shared/components/context-menu/context-menu.component.spec.ts @@ -0,0 +1,28 @@ +/* tslint:disable:no-unused-variable */ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { By } from '@angular/platform-browser'; +import { DebugElement } from '@angular/core'; + +import { ContextMenuComponent } from './context-menu.component'; + +describe('ContextMenuComponent', () => { + let component: ContextMenuComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ ContextMenuComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(ContextMenuComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/frontend/src/app/shared/components/context-menu/context-menu.component.ts b/frontend/src/app/shared/components/context-menu/context-menu.component.ts new file mode 100644 index 0000000..ad54368 --- /dev/null +++ b/frontend/src/app/shared/components/context-menu/context-menu.component.ts @@ -0,0 +1,40 @@ +import { Component, OnInit } from '@angular/core'; +import { ContextMenuService } from '../../services/context-menu.service'; + +@Component({ + selector: 'app-context-menu', + templateUrl: './context-menu.component.html', + styleUrls: ['./context-menu.component.css'], +}) +export class ContextMenuComponent implements OnInit { + isVisible = false; + position = { x: 0, y: 0 }; + menuOptions: any[] = []; + + optionsDisplayText = { + removeFromLib: 'Remove From Library', + addToLib: 'Add To Library', + addToCollection: 'Add To Collection', + optopt: 'opt', + }; + + constructor(private contextMenuService: ContextMenuService) {} + + ngOnInit() { + this.contextMenuService.contextMenuVisibility$.subscribe((visible) => { + this.isVisible = visible; + }); + + this.contextMenuService.contextMenuPosition$.subscribe((position) => { + this.position = position; + }); + + this.contextMenuService.menuOptions$.subscribe((options) => { + this.menuOptions = options; + }); + } + + onAction(action: string) { + this.contextMenuService.hideContextMenu(); + } +} diff --git a/frontend/src/app/shared/constants/context-menu-options.ts b/frontend/src/app/shared/constants/context-menu-options.ts new file mode 100644 index 0000000..8dc2a88 --- /dev/null +++ b/frontend/src/app/shared/constants/context-menu-options.ts @@ -0,0 +1,8 @@ +export const CONTEXT_MENU_OPTIONS = { + removeFromWatchlist: { label: 'Remove From Watchlist', icon: 'fas fa-download' }, + addToWatchlist: { label: 'Add To Watchlist', icon: 'fas fa-download' }, + addToLibrary: { label: 'Add to Library', icon: 'fas fa-download' }, + + + separator: { label: 'separator' }, +}; diff --git a/frontend/src/app/shared/directives/context-menu-trigger.directive.ts b/frontend/src/app/shared/directives/context-menu-trigger.directive.ts new file mode 100644 index 0000000..cfb829d --- /dev/null +++ b/frontend/src/app/shared/directives/context-menu-trigger.directive.ts @@ -0,0 +1,27 @@ +import { Directive, HostListener, Input } from '@angular/core'; +import { ContextMenuService } from '../services/context-menu.service'; + +@Directive({ + selector: '[appContextMenuTrigger]', +}) +export class ContextMenuTriggerDirective { + @Input() menuOptions: any[] = []; + + constructor(private contextMenuService: ContextMenuService) {} + + @HostListener('contextmenu', ['$event']) + onRightClick(event: MouseEvent) { + event.preventDefault(); // Prevent the default browser context menu + console.log('Right-click detected at', event.clientX, event.clientY); + this.contextMenuService.setMenuOptions(this.menuOptions); // Pass the menu options + this.contextMenuService.showContextMenu({ + x: event.clientX, + y: event.clientY - 40, + }); + } + + @HostListener('document:click') + hide() { + this.contextMenuService.hideContextMenu(); + } +} diff --git a/frontend/src/app/shared/services/context-menu.service.ts b/frontend/src/app/shared/services/context-menu.service.ts new file mode 100644 index 0000000..53dfbf5 --- /dev/null +++ b/frontend/src/app/shared/services/context-menu.service.ts @@ -0,0 +1,28 @@ +import { Injectable } from '@angular/core'; +import { Subject } from 'rxjs'; + +@Injectable({ + providedIn: 'root', +}) +export class ContextMenuService { + private contextMenuVisibility = new Subject(); + private contextMenuPosition = new Subject<{ x: number; y: number }>(); + private menuOptions = new Subject(); + + contextMenuVisibility$ = this.contextMenuVisibility.asObservable(); + contextMenuPosition$ = this.contextMenuPosition.asObservable(); + menuOptions$ = this.menuOptions.asObservable(); + + showContextMenu(position: { x: number; y: number }) { + this.contextMenuPosition.next(position); + this.contextMenuVisibility.next(true); + } + + hideContextMenu() { + this.contextMenuVisibility.next(false); + } + + setMenuOptions(options: any[]) { + this.menuOptions.next(options); + } +} diff --git a/frontend/src/app/shared/shared.module.ts b/frontend/src/app/shared/shared.module.ts index aa9d06e..d10b2ce 100644 --- a/frontend/src/app/shared/shared.module.ts +++ b/frontend/src/app/shared/shared.module.ts @@ -18,7 +18,10 @@ import { DynamicEntryListComponent } from './components/lists/dynamic-entry-list import { NotificationPopupComponent } from './components/notification-popup/notification-popup.component'; import { MinutesFormatPipe } from './pipes/minutes-format/minutes-format.pipe'; import { TwoLinesGridComponent } from './components/lists/two-lines-grid/two-lines-grid.component'; +import { ToastrModule } from 'ngx-toastr'; import { StopScrollDirective } from './directives/stop-scroll.directive'; +import { ContextMenuTriggerDirective } from './directives/context-menu-trigger.directive'; +import { ContextMenuComponent } from './components/context-menu/context-menu.component'; @NgModule({ imports: [ @@ -28,6 +31,7 @@ import { StopScrollDirective } from './directives/stop-scroll.directive'; ReactiveFormsModule, RatingModule.forRoot(), + ToastrModule.forRoot(), ], declarations: [ // * pipes @@ -37,6 +41,7 @@ import { StopScrollDirective } from './directives/stop-scroll.directive'; // * directives StopScrollDirective, + ContextMenuTriggerDirective, // ? modals SeenModalComponent, @@ -47,6 +52,8 @@ import { StopScrollDirective } from './directives/stop-scroll.directive'; DynamicEntryListComponent, TwoLinesGridComponent, NotificationPopupComponent, + + ContextMenuComponent ], exports: [ // * pipes @@ -56,6 +63,7 @@ import { StopScrollDirective } from './directives/stop-scroll.directive'; // * directives StopScrollDirective, + ContextMenuTriggerDirective, FormsModule, ReactiveFormsModule, @@ -68,6 +76,8 @@ import { StopScrollDirective } from './directives/stop-scroll.directive'; DynamicEntryListComponent, TwoLinesGridComponent, NotificationPopupComponent, + + ContextMenuComponent ], }) export class SharedModule {}