- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(lib): improved the compose function
1 parent
644588a
commit 5f826d7
Showing
8 changed files
with
673 additions
and
461 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |