Initial commit for the Angular part. We are nowhere yet.

This commit is contained in:
Amritanshu
2019-06-14 00:32:34 +05:30
parent 1a1fa7881d
commit d59c60e81d
123 changed files with 3748 additions and 374 deletions

View File

@ -0,0 +1,20 @@
import {Pipe, PipeTransform} from '@angular/core';
@Pipe({
name: 'accounting'
})
export class AccountingPipe implements PipeTransform {
constructor() {
}
transform(value: string): string {
if (value === null) {
return '';
}
const amount = +(value.replace(new RegExp('(₹ )|(,)', 'g'), ''));
return value.replace('-', '') + ((amount < 0) ? '\u00A0Cr' : '\u00A0Dr');
}
}

View File

@ -0,0 +1,12 @@
import {Pipe, PipeTransform} from '@angular/core';
@Pipe({
name: 'clear'
})
export class ClearPipe implements PipeTransform {
transform(value: any, args?: any): any {
return value === '₹ 0.00' || value === '0.00' ? '' : value;
}
}

View File

@ -0,0 +1,8 @@
<h1 mat-dialog-title>{{data.title}}</h1>
<div mat-dialog-content>
{{data.content}}
</div>
<div mat-dialog-actions>
<button mat-button [mat-dialog-close]="false" cdkFocusInitial>Cancel</button>
<button mat-button [mat-dialog-close]="true" color="warn">Ok</button>
</div>

View File

@ -0,0 +1,16 @@
import {Component, Inject} from '@angular/core';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
@Component({
selector: 'app-confirm-dialog',
templateUrl: './confirm-dialog.component.html',
styleUrls: ['./confirm-dialog.component.css']
})
export class ConfirmDialogComponent {
constructor(
public dialogRef: MatDialogRef<ConfirmDialogComponent>,
@Inject(MAT_DIALOG_DATA) public data: any) {
}
}

View File

@ -0,0 +1,36 @@
import {Injectable} from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class CookieService {
constructor() {
}
public getCookie(name: string) {
const ca: Array<string> = document.cookie.split(';');
const caLen: number = ca.length;
const cookieName = `${name}=`;
let c: string;
for (let i = 0; i < caLen; i += 1) {
c = ca[i].replace(/^\s+/g, '');
if (c.indexOf(cookieName) === 0) {
return c.substring(cookieName.length, c.length);
}
}
return '';
}
public deleteCookie(name) {
this.setCookie(name, '', -1);
}
public setCookie(name: string, value: string, expireDays: number, path: string = '') {
const d: Date = new Date();
d.setTime(d.getTime() + expireDays * 24 * 60 * 60 * 1000);
const expires: string = 'expires=' + d.toUTCString();
document.cookie = name + '=' + value + '; ' + expires + (path.length > 0 ? '; path=' + path : '');
}
}

View File

@ -0,0 +1,3 @@
img {
max-width: 100%;
}

View File

@ -0,0 +1 @@
<img [src]="data" (click)="close()">

View File

@ -0,0 +1,20 @@
import {Component, Inject} from '@angular/core';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
@Component({
selector: 'app-image-dialog',
templateUrl: './image-dialog.component.html',
styleUrls: ['./image-dialog.component.css']
})
export class ImageDialogComponent {
constructor(
public dialogRef: MatDialogRef<ImageDialogComponent>,
@Inject(MAT_DIALOG_DATA) public data: any) {
}
close(): void {
this.dialogRef.close();
}
}

View File

@ -0,0 +1,16 @@
import {Pipe, PipeTransform} from '@angular/core';
import * as moment from 'moment';
@Pipe({
name: 'localTime'
})
export class LocalTimePipe implements PipeTransform {
transform(value: string): string {
if (value === undefined) {
return '';
}
return moment(value, 'DD-MMM-YYYY HH:mm').subtract(new Date().getTimezoneOffset(), 'minutes').format('DD-MMM-YYYY HH:mm');
}
}

View File

@ -0,0 +1,35 @@
import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {ConfirmDialogComponent} from './confirm-dialog/confirm-dialog.component';
import { MatButtonModule } from '@angular/material/button';
import { MatDialogModule } from '@angular/material/dialog';
import {LocalTimePipe} from './local-time.pipe';
import {ClearPipe} from './clear.pipe';
import {AccountingPipe} from './accounting.pipe';
import {ImageDialogComponent} from './image-dialog/image-dialog.component';
@NgModule({
imports: [
CommonModule,
MatButtonModule,
MatDialogModule
],
declarations: [
ConfirmDialogComponent,
ImageDialogComponent,
AccountingPipe,
ClearPipe,
LocalTimePipe
],
entryComponents: [
ConfirmDialogComponent,
ImageDialogComponent
],
exports: [
AccountingPipe,
ClearPipe,
LocalTimePipe
]
})
export class SharedModule {
}

View File

@ -0,0 +1,18 @@
import {Injectable} from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class ToCsvService {
constructor() {
}
toCsv(headers: any, data: any[]): string {
const header = Object.keys(headers);
const replacer = (key, value) => value === null ? '' : value;
const csv = data.map(row => header.map(fieldName => JSON.stringify(row[headers[fieldName]], replacer)).join(','));
csv.unshift(header.join(','));
return csv.join('\r\n');
}
}

View File

@ -0,0 +1,50 @@
import {Injectable} from '@angular/core';
const re = /((('[^']+'|"[^"]+"|[^\s]+)\s*:\s*('[^']+'|"[^"]+"|[^\s]+))|('[^']+'|"[^"]+"|[^\s]+))/g;
@Injectable({
providedIn: 'root'
})
export class TokenizerService {
constructor() {
}
getMatches(input: string): string[] {
input = input ? input : '';
return input.match(re);
}
getPairs(input: string[]): any[] {
input = input ? input : [];
return input.reduce((accumulator, item) => {
let key,
value;
if (item.indexOf(':') === -1) {
key = '';
value = item;
} else {
key = item.substr(0, item.indexOf(':')).trim();
value = item.substr(item.indexOf(':') + 1, item.length).trim();
}
if (key.indexOf('\'') !== -1 || key.indexOf('"') !== -1) {
key = key.substring(1, key.length - 1).trim();
}
if (value.indexOf('\'') !== -1 || value.indexOf('"') !== -1) {
value = value.substring(1, value.length - 1).trim();
}
if (value !== '') {
accumulator.push({Key: key, Value: value});
}
return accumulator;
}, []);
}
isSort(key: string, value: string, sorter?: any): boolean {
const isSort = (key === '' && value.length > 1 && '+-'.indexOf(value.charAt(0)) !== -1);
return sorter !== null ? (isSort && value.substr(1) in sorter) : isSort;
}
getFilters(input: string[]) {
// input.
}
}