|
| 1 | +import { AfterViewInit, Component, forwardRef, inject } from '@angular/core'; |
| 2 | +import { NG_VALUE_ACCESSOR } from '@angular/forms'; |
| 3 | +import OfficePaste from '@intevation/tiptap-extension-office-paste'; |
| 4 | +import { Extension } from '@tiptap/core'; |
| 5 | +import { Bold } from '@tiptap/extension-bold'; |
| 6 | +import { Document } from '@tiptap/extension-document'; |
| 7 | +import { HardBreak } from '@tiptap/extension-hard-break'; |
| 8 | +import { Heading } from '@tiptap/extension-heading'; |
| 9 | +import { Paragraph } from '@tiptap/extension-paragraph'; |
| 10 | +import { Text } from '@tiptap/extension-text'; |
| 11 | +import { UndoRedo } from '@tiptap/extensions'; |
| 12 | +import { Permission } from 'src/app/domain/definitions/permission'; |
| 13 | +import { MeetingSettingsService } from 'src/app/site/pages/meetings/services/meeting-settings.service'; |
| 14 | +import { OperatorService } from 'src/app/site/services/operator.service'; |
| 15 | + |
| 16 | +import { EditorComponent } from '../../../../../../../ui/modules/editor/components/editor/editor.component'; |
| 17 | +import { |
| 18 | + OsSplit, |
| 19 | + OsSplitBulletList, |
| 20 | + OsSplitListItem, |
| 21 | + OsSplitOrderedList |
| 22 | +} from '../../../../../../../ui/modules/editor/components/editor/extensions/os-split'; |
| 23 | +import { TextStyle } from '../../../../../../../ui/modules/editor/components/editor/extensions/text-style'; |
| 24 | + |
| 25 | +@Component({ |
| 26 | + selector: `os-motion-editor`, |
| 27 | + |
| 28 | + templateUrl: `../../../../../../../ui/modules/editor/components/editor/editor.component.html`, |
| 29 | + styleUrls: [`../../../../../../../ui/modules/editor/components/editor/editor.component.scss`], |
| 30 | + providers: [{ provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => MotionEditorComponent), multi: true }], |
| 31 | + standalone: false |
| 32 | +}) |
| 33 | +export class MotionEditorComponent extends EditorComponent implements AfterViewInit { |
| 34 | + private nonManagerSetting = false; |
| 35 | + private managerSetting = false; |
| 36 | + |
| 37 | + private canManage = false; |
| 38 | + |
| 39 | + protected operator: OperatorService = inject(OperatorService); |
| 40 | + |
| 41 | + public constructor(private meetingSettingsService: MeetingSettingsService) { |
| 42 | + super(); |
| 43 | + |
| 44 | + this.nonManagerSetting = this.meetingSettingsService.instant( |
| 45 | + `motions_enable_restricted_editor_for_non_manager` |
| 46 | + ); |
| 47 | + this.managerSetting = this.meetingSettingsService.instant(`motions_enable_restricted_editor_for_manager`); |
| 48 | + |
| 49 | + this.canManage = this.operator.hasPerms(Permission.motionCanManage); |
| 50 | + } |
| 51 | + |
| 52 | + public override getExtensions(): Extension[] { |
| 53 | + if ((this.canManage && this.managerSetting) || (!this.canManage && this.nonManagerSetting)) { |
| 54 | + return [ |
| 55 | + OfficePaste, |
| 56 | + // Nodes |
| 57 | + Document, |
| 58 | + HardBreak, |
| 59 | + Heading, |
| 60 | + OsSplitBulletList, |
| 61 | + OsSplitOrderedList, |
| 62 | + OsSplitListItem, |
| 63 | + Paragraph, |
| 64 | + Text, |
| 65 | + |
| 66 | + // Marks |
| 67 | + Bold, |
| 68 | + TextStyle, |
| 69 | + |
| 70 | + // Extensions |
| 71 | + UndoRedo, |
| 72 | + OsSplit, |
| 73 | + this.ngExtension() |
| 74 | + ]; |
| 75 | + } |
| 76 | + return super.getExtensions(); |
| 77 | + } |
| 78 | +} |
0 commit comments