mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-19 10:19:27 -05:00
98 lines
3.1 KiB
TypeScript
98 lines
3.1 KiB
TypeScript
import {
|
|
CdkDragDrop,
|
|
CdkDragEnd,
|
|
CdkDragStart,
|
|
DragDropModule,
|
|
moveItemInArray,
|
|
} from '@angular/cdk/drag-drop'
|
|
import { Component } from '@angular/core'
|
|
import { TourNgBootstrapModule, TourService } from 'ngx-ui-tour-ng-bootstrap'
|
|
import { SavedView } from 'src/app/data/saved-view'
|
|
import { IfPermissionsDirective } from 'src/app/directives/if-permissions.directive'
|
|
import { SavedViewService } from 'src/app/services/rest/saved-view.service'
|
|
import { SettingsService } from 'src/app/services/settings.service'
|
|
import { ToastService } from 'src/app/services/toast.service'
|
|
import { environment } from 'src/environments/environment'
|
|
import { LogoComponent } from '../common/logo/logo.component'
|
|
import { PageHeaderComponent } from '../common/page-header/page-header.component'
|
|
import { ComponentWithPermissions } from '../with-permissions/with-permissions.component'
|
|
import { SavedViewWidgetComponent } from './widgets/saved-view-widget/saved-view-widget.component'
|
|
import { StatisticsWidgetComponent } from './widgets/statistics-widget/statistics-widget.component'
|
|
import { UploadFileWidgetComponent } from './widgets/upload-file-widget/upload-file-widget.component'
|
|
import { WelcomeWidgetComponent } from './widgets/welcome-widget/welcome-widget.component'
|
|
|
|
@Component({
|
|
selector: 'pngx-dashboard',
|
|
templateUrl: './dashboard.component.html',
|
|
styleUrls: ['./dashboard.component.scss'],
|
|
imports: [
|
|
LogoComponent,
|
|
PageHeaderComponent,
|
|
SavedViewWidgetComponent,
|
|
StatisticsWidgetComponent,
|
|
UploadFileWidgetComponent,
|
|
WelcomeWidgetComponent,
|
|
IfPermissionsDirective,
|
|
DragDropModule,
|
|
TourNgBootstrapModule,
|
|
],
|
|
})
|
|
export class DashboardComponent extends ComponentWithPermissions {
|
|
public dashboardViews: SavedView[] = []
|
|
constructor(
|
|
public settingsService: SettingsService,
|
|
public savedViewService: SavedViewService,
|
|
private tourService: TourService,
|
|
private toastService: ToastService
|
|
) {
|
|
super()
|
|
|
|
this.savedViewService.listAll().subscribe(() => {
|
|
this.dashboardViews = this.savedViewService.dashboardViews
|
|
})
|
|
}
|
|
|
|
get subtitle() {
|
|
if (this.settingsService.displayName) {
|
|
return $localize`Hello ${this.settingsService.displayName}, welcome to ${environment.appTitle}`
|
|
} else {
|
|
return $localize`Welcome to ${environment.appTitle}`
|
|
}
|
|
}
|
|
|
|
completeTour() {
|
|
if (this.tourService.getStatus() !== 0) {
|
|
this.tourService.end() // will call settingsService.completeTour()
|
|
} else {
|
|
this.settingsService.completeTour()
|
|
}
|
|
}
|
|
|
|
onDragStart(event: CdkDragStart) {
|
|
this.settingsService.globalDropzoneEnabled = false
|
|
}
|
|
|
|
onDragEnd(event: CdkDragEnd) {
|
|
this.settingsService.globalDropzoneEnabled = true
|
|
}
|
|
|
|
onDrop(event: CdkDragDrop<SavedView[]>) {
|
|
moveItemInArray(
|
|
this.dashboardViews,
|
|
event.previousIndex,
|
|
event.currentIndex
|
|
)
|
|
|
|
this.settingsService
|
|
.updateDashboardViewsSort(this.dashboardViews)
|
|
.subscribe({
|
|
next: () => {
|
|
this.toastService.showInfo($localize`Dashboard updated`)
|
|
},
|
|
error: (e) => {
|
|
this.toastService.showError($localize`Error updating dashboard`, e)
|
|
},
|
|
})
|
|
}
|
|
}
|