diff --git a/src-ui/src/app/app.module.ts b/src-ui/src/app/app.module.ts index 4a65209b9..ea366b968 100644 --- a/src-ui/src/app/app.module.ts +++ b/src-ui/src/app/app.module.ts @@ -78,6 +78,7 @@ import { SettingsService } from './services/settings.service' import { TasksComponent } from './components/manage/tasks/tasks.component' import { TourNgBootstrapModule } from 'ngx-ui-tour-ng-bootstrap' import { MailAccountEditDialogComponent } from './components/common/edit-dialog/mail-account-edit-dialog/mail-account-edit-dialog.component' +import { MailRuleEditDialogComponent } from './components/common/edit-dialog/mail-rule-edit-dialog/mail-rule-edit-dialog.component' import localeBe from '@angular/common/locales/be' import localeCs from '@angular/common/locales/cs' @@ -144,7 +145,6 @@ function initializeApp(settings: SettingsService) { TagEditDialogComponent, DocumentTypeEditDialogComponent, StoragePathEditDialogComponent, - MailAccountEditDialogComponent, TagComponent, ClearableBadge, PageHeaderComponent, @@ -184,6 +184,8 @@ function initializeApp(settings: SettingsService) { DocumentAsnComponent, DocumentCommentsComponent, TasksComponent, + MailAccountEditDialogComponent, + MailRuleEditDialogComponent, ], imports: [ BrowserModule, diff --git a/src-ui/src/app/components/common/edit-dialog/mail-rule-edit-dialog/mail-rule-edit-dialog.component.html b/src-ui/src/app/components/common/edit-dialog/mail-rule-edit-dialog/mail-rule-edit-dialog.component.html new file mode 100644 index 000000000..0b7891e81 --- /dev/null +++ b/src-ui/src/app/components/common/edit-dialog/mail-rule-edit-dialog/mail-rule-edit-dialog.component.html @@ -0,0 +1,37 @@ +
+ + + +
diff --git a/src-ui/src/app/components/common/edit-dialog/mail-rule-edit-dialog/mail-rule-edit-dialog.component.scss b/src-ui/src/app/components/common/edit-dialog/mail-rule-edit-dialog/mail-rule-edit-dialog.component.scss new file mode 100644 index 000000000..e69de29bb diff --git a/src-ui/src/app/components/common/edit-dialog/mail-rule-edit-dialog/mail-rule-edit-dialog.component.ts b/src-ui/src/app/components/common/edit-dialog/mail-rule-edit-dialog/mail-rule-edit-dialog.component.ts new file mode 100644 index 000000000..c4faf86ab --- /dev/null +++ b/src-ui/src/app/components/common/edit-dialog/mail-rule-edit-dialog/mail-rule-edit-dialog.component.ts @@ -0,0 +1,98 @@ +import { Component } from '@angular/core' +import { FormControl, FormGroup } from '@angular/forms' +import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap' +import { first } from 'rxjs' +import { EditDialogComponent } from 'src/app/components/common/edit-dialog/edit-dialog.component' +import { PaperlessCorrespondent } from 'src/app/data/paperless-correspondent' +import { PaperlessDocumentType } from 'src/app/data/paperless-document-type' +import { + MailAction, + MailActionOptions, + MailFilterAttachmentType, + MailFilterAttachmentTypeOptions, + MailMetadataCorrespondentOption, + MailMetadataCorrespondentOptionOptions, + MailMetadataTitleOption, + MailMetadataTitleOptionOptions, + PaperlessMailRule, +} from 'src/app/data/paperless-mail-rule' +import { CorrespondentService } from 'src/app/services/rest/correspondent.service' +import { DocumentTypeService } from 'src/app/services/rest/document-type.service' +import { MailRuleService } from 'src/app/services/rest/mail-rule.service' + +@Component({ + selector: 'app-mail-rule-edit-dialog', + templateUrl: './mail-rule-edit-dialog.component.html', + styleUrls: ['./mail-rule-edit-dialog.component.scss'], +}) +export class MailRuleEditDialogComponent extends EditDialogComponent { + correspondents: PaperlessCorrespondent[] + documentTypes: PaperlessDocumentType[] + + constructor( + service: MailRuleService, + activeModal: NgbActiveModal, + correspondentService: CorrespondentService, + documentTypeService: DocumentTypeService + ) { + super(service, activeModal) + + correspondentService + .listAll() + .pipe(first()) + .subscribe((result) => (this.correspondents = result.results)) + + documentTypeService + .listAll() + .pipe(first()) + .subscribe((result) => (this.documentTypes = result.results)) + } + + getCreateTitle() { + return $localize`Create new mail rule` + } + + getEditTitle() { + return $localize`Edit mail rule` + } + + getForm(): FormGroup { + return new FormGroup({ + name: new FormControl(null), + order: new FormControl(null), + account: new FormControl(null), + folder: new FormControl('INBOX'), + filter_from: new FormControl(null), + filter_subject: new FormControl(null), + filter_body: new FormControl(null), + filter_attachment_filename: new FormControl(null), + maximum_age: new FormControl(null), + attachment_type: new FormControl(MailFilterAttachmentType.Attachments), + action: new FormControl(MailAction.MarkRead), + action_parameter: new FormControl(null), + assign_title_from: new FormControl(MailMetadataTitleOption.FromSubject), + assign_tags: new FormControl(null), + assign_document_type: new FormControl(null), + assign_correspondent_from: new FormControl( + MailMetadataCorrespondentOption.FromNothing + ), + assign_correspondent: new FormControl(null), + }) + } + + get attachmentTypeOptions() { + return MailFilterAttachmentTypeOptions + } + + get actionOptions() { + return MailActionOptions + } + + get metadataTitleOptions() { + return MailMetadataTitleOptionOptions + } + + get metadataCorrespondentOptions() { + return MailMetadataCorrespondentOptionOptions + } +} diff --git a/src-ui/src/app/components/common/input/tags/tags.component.html b/src-ui/src/app/components/common/input/tags/tags.component.html index 77e25d88d..14de0f98a 100644 --- a/src-ui/src/app/components/common/input/tags/tags.component.html +++ b/src-ui/src/app/components/common/input/tags/tags.component.html @@ -7,7 +7,7 @@ [closeOnSelect]="false" [clearSearchOnAdd]="true" [hideSelected]="true" - [addTag]="createTagRef" + [addTag]="allowCreate ? createTagRef : false" addTagText="Add tag" i18n-addTagText (change)="onChange(value)" @@ -31,7 +31,7 @@ -