mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-09 09:58:20 -05:00
Working mail rule & account edit
This commit is contained in:
parent
997bff4917
commit
18ad9bcbf2
@ -9,15 +9,16 @@
|
|||||||
<div class="col">
|
<div class="col">
|
||||||
<app-input-text i18n-title title="Name" formControlName="name" [error]="error?.name"></app-input-text>
|
<app-input-text i18n-title title="Name" formControlName="name" [error]="error?.name"></app-input-text>
|
||||||
<app-input-text i18n-title title="Order" formControlName="order" [error]="error?.order"></app-input-text>
|
<app-input-text i18n-title title="Order" formControlName="order" [error]="error?.order"></app-input-text>
|
||||||
<app-input-text i18n-title title="Account" formControlName="account" [error]="error?.account"></app-input-text>
|
<app-input-select i18n-title title="Account" [items]="accounts" formControlName="account"></app-input-select>
|
||||||
<app-input-text i18n-title title="Folder" formControlName="folder" [error]="error?.folder"></app-input-text>
|
<app-input-text i18n-title title="Folder" formControlName="folder" [error]="error?.folder"></app-input-text>
|
||||||
<app-input-text i18n-title title="Filter from" formControlName="filter_from" [error]="error?.filter_from"></app-input-text>
|
|
||||||
<app-input-text i18n-title title="Filter body" formControlName="filter_body" [error]="error?.filter_body"></app-input-text>
|
|
||||||
<app-input-text i18n-title title="Filter attachment filename" formControlName="filter_attachment_filename" [error]="error?.filter_attachment_filename"></app-input-text>
|
|
||||||
</div>
|
|
||||||
<div class="col">
|
|
||||||
<app-input-number i18n-title title="Maximum age" formControlName="maximum_age" [error]="error?.maximum_age"></app-input-number>
|
<app-input-number i18n-title title="Maximum age" formControlName="maximum_age" [error]="error?.maximum_age"></app-input-number>
|
||||||
<app-input-select i18n-title title="Attachment type" [items]="attachmentTypeOptions" formControlName="attachment_type"></app-input-select>
|
<app-input-select i18n-title title="Attachment type" [items]="attachmentTypeOptions" formControlName="attachment_type"></app-input-select>
|
||||||
|
</div>
|
||||||
|
<div class="col">
|
||||||
|
<app-input-text i18n-title title="Filter from" formControlName="filter_from" [error]="error?.filter_from"></app-input-text>
|
||||||
|
<app-input-text i18n-title title="Filter subject" formControlName="filter_subject" [error]="error?.filter_subject"></app-input-text>
|
||||||
|
<app-input-text i18n-title title="Filter body" formControlName="filter_body" [error]="error?.filter_body"></app-input-text>
|
||||||
|
<app-input-text i18n-title title="Filter attachment filename" formControlName="filter_attachment_filename" [error]="error?.filter_attachment_filename"></app-input-text>
|
||||||
<app-input-select i18n-title title="Action" [items]="actionOptions" formControlName="attachment_type"></app-input-select>
|
<app-input-select i18n-title title="Action" [items]="actionOptions" formControlName="attachment_type"></app-input-select>
|
||||||
<app-input-text i18n-title title="Action parameter" formControlName="action_parameter" [error]="error?.action_parameter"></app-input-text>
|
<app-input-text i18n-title title="Action parameter" formControlName="action_parameter" [error]="error?.action_parameter"></app-input-text>
|
||||||
</div>
|
</div>
|
||||||
|
@ -5,6 +5,7 @@ import { first } from 'rxjs'
|
|||||||
import { EditDialogComponent } from 'src/app/components/common/edit-dialog/edit-dialog.component'
|
import { EditDialogComponent } from 'src/app/components/common/edit-dialog/edit-dialog.component'
|
||||||
import { PaperlessCorrespondent } from 'src/app/data/paperless-correspondent'
|
import { PaperlessCorrespondent } from 'src/app/data/paperless-correspondent'
|
||||||
import { PaperlessDocumentType } from 'src/app/data/paperless-document-type'
|
import { PaperlessDocumentType } from 'src/app/data/paperless-document-type'
|
||||||
|
import { PaperlessMailAccount } from 'src/app/data/paperless-mail-account'
|
||||||
import {
|
import {
|
||||||
MailAction,
|
MailAction,
|
||||||
MailActionOptions,
|
MailActionOptions,
|
||||||
@ -18,6 +19,7 @@ import {
|
|||||||
} from 'src/app/data/paperless-mail-rule'
|
} from 'src/app/data/paperless-mail-rule'
|
||||||
import { CorrespondentService } from 'src/app/services/rest/correspondent.service'
|
import { CorrespondentService } from 'src/app/services/rest/correspondent.service'
|
||||||
import { DocumentTypeService } from 'src/app/services/rest/document-type.service'
|
import { DocumentTypeService } from 'src/app/services/rest/document-type.service'
|
||||||
|
import { MailAccountService } from 'src/app/services/rest/mail-account.service'
|
||||||
import { MailRuleService } from 'src/app/services/rest/mail-rule.service'
|
import { MailRuleService } from 'src/app/services/rest/mail-rule.service'
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@ -26,17 +28,24 @@ import { MailRuleService } from 'src/app/services/rest/mail-rule.service'
|
|||||||
styleUrls: ['./mail-rule-edit-dialog.component.scss'],
|
styleUrls: ['./mail-rule-edit-dialog.component.scss'],
|
||||||
})
|
})
|
||||||
export class MailRuleEditDialogComponent extends EditDialogComponent<PaperlessMailRule> {
|
export class MailRuleEditDialogComponent extends EditDialogComponent<PaperlessMailRule> {
|
||||||
|
accounts: PaperlessMailAccount[]
|
||||||
correspondents: PaperlessCorrespondent[]
|
correspondents: PaperlessCorrespondent[]
|
||||||
documentTypes: PaperlessDocumentType[]
|
documentTypes: PaperlessDocumentType[]
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
service: MailRuleService,
|
service: MailRuleService,
|
||||||
activeModal: NgbActiveModal,
|
activeModal: NgbActiveModal,
|
||||||
|
accountService: MailAccountService,
|
||||||
correspondentService: CorrespondentService,
|
correspondentService: CorrespondentService,
|
||||||
documentTypeService: DocumentTypeService
|
documentTypeService: DocumentTypeService
|
||||||
) {
|
) {
|
||||||
super(service, activeModal)
|
super(service, activeModal)
|
||||||
|
|
||||||
|
accountService
|
||||||
|
.listAll()
|
||||||
|
.pipe(first())
|
||||||
|
.subscribe((result) => (this.accounts = result.results))
|
||||||
|
|
||||||
correspondentService
|
correspondentService
|
||||||
.listAll()
|
.listAll()
|
||||||
.pipe(first())
|
.pipe(first())
|
||||||
|
@ -234,8 +234,8 @@
|
|||||||
|
|
||||||
<li *ngFor="let account of mailAccounts" class="list-group-item" [formGroupName]="account.id">
|
<li *ngFor="let account of mailAccounts" class="list-group-item" [formGroupName]="account.id">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col"><button class="btn btn-link p-0" type="button" (click)="editMailAccount(account)">{{account.name}}</button></div>
|
<div class="col d-flex align-items-center"><button class="btn btn-link p-0" type="button" (click)="editMailAccount(account)">{{account.name}}</button></div>
|
||||||
<div class="col">{{account.imap_server}}</div>
|
<div class="col d-flex align-items-center">{{account.imap_server}}</div>
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<div class="btn-group">
|
<div class="btn-group">
|
||||||
<button class="btn btn-primary" type="button" (click)="editMailAccount(account)" i18n>Edit</button>
|
<button class="btn btn-primary" type="button" (click)="editMailAccount(account)" i18n>Edit</button>
|
||||||
@ -261,8 +261,8 @@
|
|||||||
|
|
||||||
<li *ngFor="let rule of mailRules" class="list-group-item" [formGroupName]="rule.id">
|
<li *ngFor="let rule of mailRules" class="list-group-item" [formGroupName]="rule.id">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col"><button class="btn btn-link p-0" type="button" (click)="editMailRule(rule)">{{rule.name}}</button></div>
|
<div class="col d-flex align-items-center"><button class="btn btn-link p-0" type="button" (click)="editMailRule(rule)">{{rule.name}}</button></div>
|
||||||
<div class="col">{{rule.account.name}}</div>
|
<div class="col d-flex align-items-center">{{(mailAccountService.getCached(rule.account) | async)?.name}}</div>
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<div class="btn-group">
|
<div class="btn-group">
|
||||||
<button class="btn btn-primary" type="button" (click)="editMailRule(rule)" i18n>Edit</button>
|
<button class="btn btn-primary" type="button" (click)="editMailRule(rule)" i18n>Edit</button>
|
||||||
|
@ -31,7 +31,7 @@ import { ViewportScroller } from '@angular/common'
|
|||||||
import { TourService } from 'ngx-ui-tour-ng-bootstrap'
|
import { TourService } from 'ngx-ui-tour-ng-bootstrap'
|
||||||
import { PaperlessMailAccount } from 'src/app/data/paperless-mail-account'
|
import { PaperlessMailAccount } from 'src/app/data/paperless-mail-account'
|
||||||
import { PaperlessMailRule } from 'src/app/data/paperless-mail-rule'
|
import { PaperlessMailRule } from 'src/app/data/paperless-mail-rule'
|
||||||
import { MailAccountService as MailAccountService } from 'src/app/services/rest/mail-account.service'
|
import { MailAccountService } from 'src/app/services/rest/mail-account.service'
|
||||||
import { MailRuleService } from 'src/app/services/rest/mail-rule.service'
|
import { MailRuleService } from 'src/app/services/rest/mail-rule.service'
|
||||||
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
|
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
|
||||||
import { MailAccountEditDialogComponent } from '../../common/edit-dialog/mail-account-edit-dialog/mail-account-edit-dialog.component'
|
import { MailAccountEditDialogComponent } from '../../common/edit-dialog/mail-account-edit-dialog/mail-account-edit-dialog.component'
|
||||||
@ -477,28 +477,30 @@ export class SettingsComponent
|
|||||||
}
|
}
|
||||||
|
|
||||||
editMailAccount(account: PaperlessMailAccount) {
|
editMailAccount(account: PaperlessMailAccount) {
|
||||||
console.log(account)
|
|
||||||
|
|
||||||
var modal = this.modalService.open(MailAccountEditDialogComponent, {
|
var modal = this.modalService.open(MailAccountEditDialogComponent, {
|
||||||
backdrop: 'static',
|
backdrop: 'static',
|
||||||
size: 'xl',
|
size: 'xl',
|
||||||
})
|
})
|
||||||
modal.componentInstance.dialogMode = 'edit'
|
modal.componentInstance.dialogMode = 'edit'
|
||||||
modal.componentInstance.object = account
|
modal.componentInstance.object = account
|
||||||
// TODO: saving
|
modal.componentInstance.success
|
||||||
// modal.componentInstance.success
|
.pipe(takeUntil(this.unsubscribeNotifier))
|
||||||
// .pipe(
|
.subscribe({
|
||||||
// switchMap((newStoragePath) => {
|
next: (newMailAccount) => {
|
||||||
// return this.storagePathService
|
this.toastService.showInfo(
|
||||||
// .listAll()
|
$localize`Saved account "${newMailAccount.name}".`
|
||||||
// .pipe(map((storagePaths) => ({ newStoragePath, storagePaths })))
|
)
|
||||||
// })
|
this.mailAccountService.listAll().subscribe((r) => {
|
||||||
// )
|
this.mailAccounts = r.results
|
||||||
// .pipe(takeUntil(this.unsubscribeNotifier))
|
this.initialize()
|
||||||
// .subscribe(({ newStoragePath, storagePaths }) => {
|
})
|
||||||
// this.storagePaths = storagePaths.results
|
},
|
||||||
// this.documentForm.get('storage_path').setValue(newStoragePath.id)
|
error: (e) => {
|
||||||
// })
|
this.toastService.showError(
|
||||||
|
$localize`Error saving account: ${e.toString()}.`
|
||||||
|
)
|
||||||
|
},
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteMailAccount(account: PaperlessMailAccount) {
|
deleteMailAccount(account: PaperlessMailAccount) {
|
||||||
@ -517,28 +519,31 @@ export class SettingsComponent
|
|||||||
}
|
}
|
||||||
|
|
||||||
editMailRule(rule: PaperlessMailRule) {
|
editMailRule(rule: PaperlessMailRule) {
|
||||||
console.log(rule)
|
|
||||||
|
|
||||||
var modal = this.modalService.open(MailRuleEditDialogComponent, {
|
var modal = this.modalService.open(MailRuleEditDialogComponent, {
|
||||||
backdrop: 'static',
|
backdrop: 'static',
|
||||||
size: 'xl',
|
size: 'xl',
|
||||||
})
|
})
|
||||||
modal.componentInstance.dialogMode = 'edit'
|
modal.componentInstance.dialogMode = 'edit'
|
||||||
modal.componentInstance.object = rule
|
modal.componentInstance.object = rule
|
||||||
// TODO: saving
|
modal.componentInstance.success
|
||||||
// modal.componentInstance.success
|
.pipe(takeUntil(this.unsubscribeNotifier))
|
||||||
// .pipe(
|
.subscribe({
|
||||||
// switchMap((newStoragePath) => {
|
next: (newMailRule) => {
|
||||||
// return this.storagePathService
|
this.toastService.showInfo(
|
||||||
// .listAll()
|
$localize`Saved rule "${newMailRule.name}".`
|
||||||
// .pipe(map((storagePaths) => ({ newStoragePath, storagePaths })))
|
)
|
||||||
// })
|
this.mailRuleService.listAll().subscribe((r) => {
|
||||||
// )
|
this.mailRules = r.results
|
||||||
// .pipe(takeUntil(this.unsubscribeNotifier))
|
|
||||||
// .subscribe(({ newStoragePath, storagePaths }) => {
|
this.initialize()
|
||||||
// this.storagePaths = storagePaths.results
|
})
|
||||||
// this.documentForm.get('storage_path').setValue(newStoragePath.id)
|
},
|
||||||
// })
|
error: (e) => {
|
||||||
|
this.toastService.showError(
|
||||||
|
$localize`Error saving rule: ${e.toString()}.`
|
||||||
|
)
|
||||||
|
},
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteMailRule(rule: PaperlessMailRule) {
|
deleteMailRule(rule: PaperlessMailRule) {
|
||||||
|
@ -101,7 +101,7 @@ export interface PaperlessMailRule extends ObjectWithId {
|
|||||||
|
|
||||||
order: number
|
order: number
|
||||||
|
|
||||||
account: PaperlessMailAccount
|
account: number // PaperlessMailAccount.id
|
||||||
|
|
||||||
folder: string
|
folder: string
|
||||||
|
|
||||||
@ -123,11 +123,11 @@ export interface PaperlessMailRule extends ObjectWithId {
|
|||||||
|
|
||||||
assign_title_from: MailMetadataTitleOption
|
assign_title_from: MailMetadataTitleOption
|
||||||
|
|
||||||
assign_tags?: PaperlessTag[]
|
assign_tags?: number[] // PaperlessTag.id
|
||||||
|
|
||||||
assign_document_type?: PaperlessDocumentType
|
assign_document_type?: number // PaperlessDocumentType.id
|
||||||
|
|
||||||
assign_correspondent_from?: MailMetadataCorrespondentOption
|
assign_correspondent_from?: MailMetadataCorrespondentOption
|
||||||
|
|
||||||
assign_correspondent?: PaperlessCorrespondent
|
assign_correspondent?: number // PaperlessCorrespondent.id
|
||||||
}
|
}
|
||||||
|
@ -716,7 +716,17 @@ class MailAccountSerializer(serializers.ModelSerializer):
|
|||||||
return mail_account
|
return mail_account
|
||||||
|
|
||||||
|
|
||||||
|
class AccountField(serializers.PrimaryKeyRelatedField):
|
||||||
|
def get_queryset(self):
|
||||||
|
return MailAccount.objects.all()
|
||||||
|
|
||||||
|
|
||||||
class MailRuleSerializer(serializers.ModelSerializer):
|
class MailRuleSerializer(serializers.ModelSerializer):
|
||||||
|
account = AccountField(allow_null=True)
|
||||||
|
assign_correspondent = CorrespondentField(allow_null=True)
|
||||||
|
assign_tags = TagsField(many=True)
|
||||||
|
assign_document_type = DocumentTypeField(allow_null=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = MailRule
|
model = MailRule
|
||||||
depth = 1
|
depth = 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user