Front: add context menu UI
This commit is contained in:
1 parent
31d38d8da9
commit
bd65181da3
9 files changed
+173
-1
No files matched your search
@@ -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;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<div *ngIf="isVisible" [ngStyle]="{'top.px': position.y, 'left.px': position.x}" class="context-menu">
|
||||
<ul>
|
||||
<li *ngFor="let option of menuOptions" (click)="onAction(option)">
|
||||
{{ option }}
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
@@ -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<ContextMenuComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ ContextMenuComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(ContextMenuComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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' },
|
||||
};
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Subject } from 'rxjs';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class ContextMenuService {
|
||||
private contextMenuVisibility = new Subject<boolean>();
|
||||
private contextMenuPosition = new Subject<{ x: number; y: number }>();
|
||||
private menuOptions = new Subject<any[]>();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -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 {}
|
||||
Reference in new issue
Block a user