Skip to content

Commit

Permalink
Merge pull request #4 from xpert-ai/develop
Browse files Browse the repository at this point in the history
Email templates
  • Loading branch information
tiven-w authored Dec 2, 2024
2 parents 1b6cd47 + d8ae54a commit b3bf986
Show file tree
Hide file tree
Showing 231 changed files with 889 additions and 4,944 deletions.
1 change: 1 addition & 0 deletions apps/cloud/src/app/@core/constants/app.constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { API_PREFIX } from '@metad/cloud/state'
export const API_EMAIL_TEMPLATE = API_PREFIX + '/email-template'
export const API_VISITS = API_PREFIX + '/visits'
export const API_FEEDS = API_PREFIX + '/feeds'
export const API_TAG = API_PREFIX + '/tags'
Expand Down
31 changes: 16 additions & 15 deletions apps/cloud/src/app/@core/services/email-template.service.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
import { HttpClient } from '@angular/common/http'
import { Injectable } from '@angular/core'
import { API_PREFIX, OrganizationBaseCrudService } from '@metad/cloud/state'
import {
ICustomizableEmailTemplate,
ICustomizeEmailTemplateFindInput,
IEmailTemplate,
IEmailTemplateFindInput,
IEmailTemplateSaveInput
} from '@metad/contracts'
import { API_PREFIX } from '@metad/cloud/state'
import { firstValueFrom } from 'rxjs'
import { API_EMAIL_TEMPLATE } from '../constants/app.constants'

@Injectable({
providedIn: 'root'
})
export class EmailTemplateService {
constructor(private http: HttpClient) {}

getAll(
relations?: string[],
findInput?: IEmailTemplateFindInput
): Promise<{ items: IEmailTemplate[]; total: number }> {
const data = JSON.stringify({ relations, findInput })
return firstValueFrom(
this.http.get<{ items: IEmailTemplate[]; total: number }>(`${API_PREFIX}/email-template`, {
params: { data }
})
)
export class EmailTemplateService extends OrganizationBaseCrudService<IEmailTemplate> {
constructor(private http: HttpClient) {
super(API_EMAIL_TEMPLATE)
}

// getAll(
// relations?: string[],
// findInput?: IEmailTemplateFindInput
// ) {
// const data = JSON.stringify({ relations, findInput })
// return this.http.get<{ items: IEmailTemplate[]; total: number }>(`${API_PREFIX}/email-template`, {
// params: { data }
// })
// }

getTemplate(findInput?: ICustomizeEmailTemplateFindInput): Promise<ICustomizableEmailTemplate> {
const data = JSON.stringify({ findInput })
return firstValueFrom(
Expand Down
4 changes: 4 additions & 0 deletions apps/cloud/src/app/@core/services/languages.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import { toParams } from '@metad/ocap-angular/core';
export class LanguagesService {
constructor(private http: HttpClient) { }

getAll() {
return this.http.get<{ items: ILanguage[] }>(`${API_PREFIX}/languages`)
}

insertLanguage(createLanguage: ILanguage): Promise<ILanguage> {
return firstValueFrom(
this.http.post<ILanguage>(`${API_PREFIX}/languages`, createLanguage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
[(ngModel)]="selectedLanguageCode"
[selectOptions]="languagesOptions()"
[valueKey]="'key'"
searchable
>
<mat-spinner *ngIf="loading" ngmSuffix color="accent" strokeWidth="2" diameter="20"></mat-spinner>
@if (loading()) {
<ngm-spin ngmSuffix small />
}
</ngm-select>
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import { filter, tap } from 'rxjs/operators';
import { FormsModule, NG_VALUE_ACCESSOR } from '@angular/forms';
import { CommonModule } from '@angular/common';
import { MatFormFieldAppearance } from '@angular/material/form-field';
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
import { TranslationBaseComponent } from '../translation-base.component';
import { NgmSelectComponent } from '@metad/ocap-angular/common';
import { NgmSelectComponent, NgmSpinComponent } from '@metad/ocap-angular/common';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';

@Component({
Expand All @@ -18,8 +17,8 @@ import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
FormsModule,
TranslateModule,

MatProgressSpinnerModule,
NgmSelectComponent
NgmSelectComponent,
NgmSpinComponent
],
selector: 'pac-language-selector',
templateUrl: './language-selector.component.html',
Expand All @@ -36,8 +35,6 @@ export class LanguageSelectorComponent extends TranslationBaseComponent implemen
readonly destroyRef = inject(DestroyRef)

languages = signal<ILanguage[]>([])
// languages: ILanguage[];
loading: boolean;
onChange: any = () => { }
onTouch: any = () => { }

Expand Down Expand Up @@ -111,6 +108,9 @@ export class LanguageSelectorComponent extends TranslationBaseComponent implemen

@Output() selectedLanguageEvent = new EventEmitter<ILanguage>();

// States
readonly loading = signal(false)

constructor(
private readonly languagesService: LanguagesService,
private readonly store: Store,
Expand Down Expand Up @@ -165,11 +165,11 @@ export class LanguageSelectorComponent extends TranslationBaseComponent implemen
color: '#' + Math.floor(Math.random() * 16777215).toString(16),
description: ''
};
this.loading = true;
this.loading.set(true);
const language = await this.languagesService.insertLanguage(
newLanguage
);
this.loading = false;
this.loading.set(false);
return language;
};

Expand Down
23 changes: 13 additions & 10 deletions apps/cloud/src/app/@shared/smtp/smtp.component.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
<formly-form #formly class="flex-1 self-stretch" [form]="form" [fields]="schema" [model]="customSmtp"
(modelChange)="onFormChange(customSmtp)">
<formly-form #formly class="flex-1 self-stretch"
[form]="form"
[fields]="schema"
[model]="customSmtp"
(modelChange)="onFormChange(customSmtp)">
</formly-form>

<div ngmButtonGroup>
<button mat-stroked-button displayDensity="cosy" color="accent" [disabled]="isValidated"
(click)="validateSmtp()">
{{ 'PAC.ACTIONS.Validate' | translate: {Default: 'Validate'} }}
</button>
<button mat-stroked-button displayDensity="cosy" color="accent" [disabled]="isValidated()"
(click)="validateSmtp()">
{{ 'PAC.ACTIONS.Validate' | translate: {Default: 'Validate'} }}
</button>

<button mat-raised-button displayDensity="cosy" color="primary" [disabled]="!isValidated || form.invalid"
(click)="onSubmit()">
{{ 'PAC.ACTIONS.Save' | translate: {Default: 'Save'} }}
</button>
<button mat-raised-button displayDensity="cosy" color="primary" [disabled]="!isValidated() || form.invalid"
(click)="onSubmit()">
{{ 'PAC.ACTIONS.Save' | translate: {Default: 'Save'} }}
</button>
</div>
12 changes: 6 additions & 6 deletions apps/cloud/src/app/@shared/smtp/smtp.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AfterViewInit, ChangeDetectorRef, Component, DestroyRef, Input, OnChanges, OnInit, SimpleChanges, inject } from '@angular/core'
import { AfterViewInit, ChangeDetectorRef, Component, DestroyRef, Input, OnChanges, OnInit, SimpleChanges, inject, signal } from '@angular/core'
import { FormBuilder, FormControl, FormGroup, FormsModule, ReactiveFormsModule, Validators } from '@angular/forms'
import { MatButtonModule } from '@angular/material/button'
import { ActivatedRoute } from '@angular/router'
Expand Down Expand Up @@ -49,7 +49,7 @@ export class SMTPComponent extends TranslationBaseComponent implements OnInit, O
]
customSmtp: ICustomSmtp = {} as ICustomSmtp
user: IUser
isValidated: boolean
readonly isValidated = signal(false)

/*
* Income Mutation Form
Expand Down Expand Up @@ -199,7 +199,7 @@ export class SMTPComponent extends TranslationBaseComponent implements OnInit, O
const newVal = values[1]
if ((newVal.username && oldVal.username) || (newVal.host && oldVal.host)) {
if (newVal.username !== oldVal.username || newVal.host !== oldVal.host) {
this.isValidated = false
this.isValidated.set(false)
}
}
})
Expand Down Expand Up @@ -244,7 +244,7 @@ export class SMTPComponent extends TranslationBaseComponent implements OnInit, O
*/
patchValue() {
if (this.customSmtp) {
this.isValidated = this.customSmtp.isValidate ? true : false
this.isValidated.set(this.customSmtp.isValidate ? true : false)
this.form.patchValue({
id: this.customSmtp.id,
host: this.customSmtp.host,
Expand Down Expand Up @@ -325,10 +325,10 @@ export class SMTPComponent extends TranslationBaseComponent implements OnInit, O
try {
const smtp = this.form.getRawValue()
await this.customSmtpService.validateSMTPSetting(smtp)
this.isValidated = true
this.isValidated.set(true)
this.toastrService.success(this.getTranslation('TOASTR.TITLE.SUCCESS', { Default: 'Success' }))
} catch (error) {
this.isValidated = false
this.isValidated.set(false)
this.toastrService.error(this.getTranslation('TOASTR.MESSAGE.ERRORS', { Default: 'Errors' }))
}
}
Expand Down

This file was deleted.

Loading

0 comments on commit b3bf986

Please sign in to comment.