Skip to content

Commit

Permalink
fix(lib): improved the compose function
Browse files Browse the repository at this point in the history
AnthonyNahas committed Nov 25, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 644588a commit 5f826d7
Showing 8 changed files with 673 additions and 461 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
"scripts": {
"ng": "ng",
"start": "ng serve",
"start:hmr": "ng serve --hmr",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
1,000 changes: 544 additions & 456 deletions src/app/app.component.html

Large diffs are not rendered by default.

21 changes: 19 additions & 2 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
import { Component } from '@angular/core';
import { Component, OnInit } from '@angular/core';
import { Mailto } from '../ngx-mailto/mailto';
import { NgxMailtoService } from '../ngx-mailto/ngx-mailto.service';

@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
export class AppComponent implements OnInit {
title = 'ngx-mailto-demo';

receiver1 = 'anthony.na@hotmail.de';
receiver2 = 'testa@gmail.de';


constructor(private mailtoService: NgxMailtoService) {
}

ngOnInit(): void {
const mailto: Mailto = {
cc: [],
subject: 'Just only a test!'
};
console.log(this.mailtoService.compose(mailto));
}
}
9 changes: 6 additions & 3 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { NgxMailtoModule } from '../ngx-mailto/ngx-mailto.module';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
@@ -10,9 +11,11 @@ import { AppComponent } from './app.component';
],
imports: [
BrowserModule.withServerTransition({ appId: 'serverApp' }),
AppRoutingModule
AppRoutingModule,
NgxMailtoModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
export class AppModule {
}
14 changes: 14 additions & 0 deletions src/ngx-mailto/mailto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* @author Anthony Nahas
* @since 25.11.2020
* @version 1.0
*
* All properties are optional
*/
export interface Mailto {
receiver?: string | string[];
subject?: string;
cc?: string | string[];
bcc?: string | string[];
body?: string;
}
12 changes: 12 additions & 0 deletions src/ngx-mailto/ngx-mailto.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';



@NgModule({
declarations: [],
imports: [
CommonModule
]
})
export class NgxMailtoModule { }
16 changes: 16 additions & 0 deletions src/ngx-mailto/ngx-mailto.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';

import { NgxMailtoService } from './ngx-mailto.service';

describe('NgxMailtoService', () => {
let service: NgxMailtoService;

beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(NgxMailtoService);
});

it('should be created', () => {
expect(service).toBeTruthy();
});
});
61 changes: 61 additions & 0 deletions src/ngx-mailto/ngx-mailto.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { isPlatformBrowser } from '@angular/common';
import { Inject, Injectable, PLATFORM_ID } from '@angular/core';
import { Mailto } from './mailto';

@Injectable({
providedIn: 'root'
})
export class NgxMailtoService {

// tslint:disable-next-line:ban-types
constructor(@Inject(PLATFORM_ID) private platformId: Object) {
}

isClientSide(): boolean {
return isPlatformBrowser(this.platformId);
}

compose(value: Mailto): string | void {
let link = 'mailto:';
let properties = [];
if (this.isClientSide()) {
if (value.receiver) {
if (typeof value.receiver === 'string') {
link += value.receiver;
} else {
link += value.receiver.join();
}
}
if (value.cc) {
if (typeof value.cc === 'string') {
// link += `?cc=${value.cc}`;
properties.push(`cc=${value.cc}`);
} else {
// link += `?cc=${value.cc.join()}`;
properties.push(`cc=${value.cc.join()}`);
}
}
if (value.bcc) {
if (typeof value.bcc === 'string') {
// link += `?bcc=${value.bcc}`;
properties.push(`bcc=${value.bcc}`);
} else {
// link += `?bcc=${value.bcc.join()}`;
properties.push(`bcc=${value.bcc.join()}`);
}
}
if (value.subject) {
// link += `?subject=${value.subject}`;
properties.push(`subject=${value.subject}`);
}
if (value.body) {
// link += `?body=${value.body}`;
properties.push(`body=${value.body}`);
}
if (properties.length > 0) {
link += `?${properties.join('&')}`;
}
return link;
}
}
}

0 comments on commit 5f826d7

Please sign in to comment.