Commit cbc7e3fa2b8ad11880163d1763565dc40eaa9edf

Authored by Nikita Kulshreshtha
1 parent de5f4fe0

merged code from AIAAdminApi

400-SOURCECODE/Admin/src/app/components/SubscriptionPrice/subscriptionprice.component.html 0 → 100644
  1 +<div class="row">
  2 + <!-- main-heading -->
  3 + <div class="col-sm-12 pageHeading">
  4 + <h4>Subscription Price</h4>
  5 + </div>
  6 + <!-- main-heading -->
  7 +
  8 + <ng-template #template>
  9 + <div class="modal-header">
  10 + <h4 class="modal-title pull-left">Delete</h4>
  11 + <button type="button" class="close pull-right" aria-label="Close" (click)="modalRef.hide()">
  12 + <span aria-hidden="true">&times;</span>
  13 + </button>
  14 + </div>
  15 + <div class="modal-body">
  16 + <p>Do you want to delete the selected subscription prices?</p>
  17 + </div>
  18 + <div class="modal-footer">
  19 + <button type="button" class="btn btn-primary btn-sm" (click)="DeleteSubscriptionPrices()" >Yes</button>
  20 + <button type="button" class="btn btn-primary btn-sm" (click)="modalRef.hide()" >No</button>
  21 + </div>
  22 + </ng-template>
  23 +
  24 + <ng-template #templatesuccess>
  25 + <div class="modal-header">
  26 + <h4 class="modal-title pull-left">Confirmation</h4>
  27 + <button type="button" class="close pull-right" aria-label="Close" (click)="modalRef.hide()">
  28 + <span aria-hidden="true">&times;</span>
  29 + </button>
  30 + </div>
  31 + <div class="modal-body" [innerHTML]="modalAlerts">
  32 + </div>
  33 + <div class="modal-footer">
  34 + </div>
  35 + </ng-template>
  36 +
  37 + <!-- container -->
  38 + <div [className]="divClass">
  39 +
  40 + <div class="container-fluid main-full">
  41 + <!-- form -->
  42 + <form class="form-horizontal" [formGroup]="subscriptionPriceFrm" (submit)="UpdateSubscriptionPrices(templatesuccess)">
  43 + <div [style.visibility]="(Mode == 'Search') ? 'visible' : 'hidden'" class="row">
  44 +
  45 + <div class="well marginBtm12">
  46 + <div class="form-group" *ngIf="alerts != ''">
  47 + <div class="marginBtm12 text-center">
  48 + <div class="alert alert-danger" [innerHTML]="alerts">
  49 + </div>
  50 + </div>
  51 + </div>
  52 + <!--tab-content-->
  53 + <div>
  54 + <!-- Nav tabs -->
  55 + <ul class="nav nav-tabs" role="tablist">
  56 + <li role="presentation" class="active"><a aria-controls="higher-edu" href="#" (click)="SearchSubscriptionPrices(1)" role="tab" data-toggle="tab">Higher Education Instructor</a></li>
  57 + <li role="presentation"><a aria-controls="higher-school" href="#" (click)="SearchSubscriptionPrices(2)" role="tab" data-toggle="tab">Higher School Instructor</a></li>
  58 + <li role="presentation"><a aria-controls="higher-student" href="#" (click)="SearchSubscriptionPrices(3)" role="tab" data-toggle="tab">Higher Education Student</a></li>
  59 + <li role="presentation"><a aria-controls="higher-school-student" href="#" (click)="SearchSubscriptionPrices(4)" role="tab" data-toggle="tab">Higher School Student</a></li>
  60 + <li role="presentation"><a aria-controls="public-library" href="#" (click)="SearchSubscriptionPrices(5)" role="tab" data-toggle="tab">Public Library</a></li>
  61 + <li role="presentation"><a aria-controls="academic-library" href="#" (click)="SearchSubscriptionPrices(6)" role="tab" data-toggle="tab">Academic Library</a></li>
  62 + </ul>
  63 +
  64 + <!-- Tab panes -->
  65 + <div class="tab-content">
  66 + <!--first-table-->
  67 + <div role="tabpanel" class="tab-pane active" id="higher-edu">
  68 + <div class="table-responsive blue">
  69 + <table class="table table-condensed table-bordered margin-btm0 table-striped table-hover">
  70 + <thead>
  71 + <tr>
  72 + <th>Select</th>
  73 + <th>Subscription Type</th>
  74 + <th>Duration(in Month)</th>
  75 + <th>Price</th>
  76 + <th>Active</th>
  77 + </tr>
  78 + </thead>
  79 + <tbody>
  80 + <tr *ngFor="let item of this.subscriptionPriceFrm.controls['subscriptionPrices'].value; let i = index">
  81 + <td>
  82 + <input type="hidden" [(contenteditableModel)]="item.Id">
  83 + <input type="hidden" [(contenteditableModel)]="item.EditionId">
  84 + <input type="checkbox" (change)="onChange(i, item.Id, $event.target.checked)">
  85 + </td>
  86 + <td contenteditable="true" [(contenteditableModel)]="item.Title">{{item.Title}}</td>
  87 + <td contenteditable="true" [(contenteditableModel)]="item.Duration">{{item.Duration}}</td>
  88 + <td contenteditable="true" [(contenteditableModel)]="item.Price">{{item.Price | number : '1.2'}}</td>
  89 + <td>
  90 + <input type="checkbox" [(checked)]="item.IsActive" [(contenteditableModel)]="item.IsActive">
  91 + </td>
  92 + </tr>
  93 + </tbody>
  94 + </table>
  95 + </div>
  96 + </div>
  97 + <!--first-table-->
  98 +
  99 + <div class="row">
  100 + <div class="col-sm-12 marginTop20 text-center">
  101 + <button class="btn btn-primary btn-sm" type="button" (click)="AddSubscriptionPrice(templatesuccess)"><i class="fa fa-plus-circle"></i> Add</button>
  102 + <button class="btn btn-primary btn-sm" type="button" (click)="openModal(template)"><i class="fa fa-trash"></i> Delete</button>
  103 + <button class="btn btn-primary btn-sm" type="submit"><i class="fa fa-check"></i> Apply</button>
  104 + </div>
  105 + </div>
  106 +
  107 + </div>
  108 + </div>
  109 + <!--tab-content-->
  110 + </div>
  111 + </div>
  112 + </form>
  113 + <div style="position: absolute; z-index: 100; width: 80%" [style.top]="topPos" [style.visibility]="(Mode=='Add') ? 'visible' : 'hidden'" class="well">
  114 + <div class="row">
  115 + <div class="col-sm-12">
  116 + <div class="panel-body">
  117 + <!-- form -->
  118 + <form class="form-horizontal" [formGroup]="insertSubscriptionPriceFrm" (submit)="InsertSubscriptionPrice(templatesuccess)">
  119 + <div class="form-group" *ngIf="alerts != ''">
  120 + <div class="col-xs-12">
  121 + <div class="alert alert-danger" [innerHTML]="alerts">
  122 + </div>
  123 + </div>
  124 + </div>
  125 +
  126 + <div class="form-group">
  127 + <label for="title" class="col-sm-4 control-label">Title <span class="red">*</span> :</label>
  128 + <div class="col-sm-7">
  129 + <input type="hidden" formControlName="editionId">
  130 + <input type="hidden" formControlName="subscriptionPriceId">
  131 + <input type="text" class="form-control" id="title" formControlName="title" maxlength="50">
  132 + <div *ngIf="insertSubscriptionPriceFrm.controls.title.hasError('required') && insertSubscriptionPriceFrm.controls.title.dirty" class="alert alert-danger" style="padding: 2px; margin-bottom: 2px;">Subscription title is required</div>
  133 + </div>
  134 + </div>
  135 +
  136 + <div class="form-group">
  137 + <label for="price" class="col-sm-4 control-label">Price <span class="red">*</span> :</label>
  138 + <div class="col-sm-7">
  139 + <input type="text" class="form-control" id="price" formControlName="price" maxlength="10">
  140 + <div *ngIf="insertSubscriptionPriceFrm.controls.price.hasError('required') && insertSubscriptionPriceFrm.controls.price.dirty" class="alert alert-danger" style="padding: 2px; margin-bottom: 2px;">Subscription price is required</div>
  141 + <div *ngIf="insertSubscriptionPriceFrm.controls.price.hasError('pattern') && insertSubscriptionPriceFrm.controls.price.dirty" class="alert alert-danger" style="padding: 2px; margin-bottom: 2px;">Subscription price must be numeric</div>
  142 + </div>
  143 + </div>
  144 +
  145 + <div class="form-group">
  146 + <label for="duration" class="col-sm-4 control-label">Duration <span class="red">*</span> :</label>
  147 + <div class="col-sm-7">
  148 + <input type="text" class="form-control" id="duration" formControlName="duration" maxlength="2">
  149 + <div *ngIf="insertSubscriptionPriceFrm.controls.duration.hasError('required') && insertSubscriptionPriceFrm.controls.duration.dirty" class="alert alert-danger" style="padding: 2px; margin-bottom: 2px;">Subscription duration is required</div>
  150 + <div *ngIf="insertSubscriptionPriceFrm.controls.duration.hasError('pattern') && insertSubscriptionPriceFrm.controls.duration.dirty" class="alert alert-danger" style="padding: 2px; margin-bottom: 2px;">Subscription duration must be numeric</div>
  151 + </div>
  152 + </div>
  153 +
  154 + <div class="form-group">
  155 + <label for="status" class="col-sm-4 control-label">Status :</label>
  156 + <div class="col-sm-7">
  157 + <label class="radio-inline">
  158 + <input name="isActive" value="true" type="radio" formControlName="isActive">
  159 + Active
  160 + </label>
  161 + <label class="radio-inline">
  162 + <input name="isActive" value="false" type="radio" formControlName="isActive">
  163 + Inactive
  164 + </label>
  165 + </div>
  166 + </div>
  167 +
  168 + <div class="form-group">
  169 + <div class="col-sm-offset-4 col-sm-7 mar-top17">
  170 + <button type="submit" [disabled]="!insertSubscriptionPriceFrm.valid" class="btn btn-primary btn-sm"><i class="fa fa-plus-circle"></i> Save</button>
  171 + <button type="button" (click)="CancelAdd()" class="btn btn-primary btn-sm"><i class="fa fa-times-circle"></i> Cancel</button>
  172 + </div>
  173 + </div>
  174 +
  175 + </form>
  176 + <!-- form -->
  177 +
  178 + <!--modal-->
  179 + <div class="modal fade bs-example-modal-sm text-left" tabindex="-1" role="dialog" id="mymodal">
  180 + <div class="modal-dialog modal-sm" role="document">
  181 + <div class="modal-content">
  182 + <div class="modal-header annotation-modal-header ui-draggable-handle">
  183 + <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
  184 + <h4 class="modal-title" id="">Alert</h4>
  185 + </div>
  186 + <div class="modal-body">
  187 + <h5>Please select subscription to delete.</h5>
  188 + </div>
  189 + <div class="modal-footer">
  190 + <div class="row">
  191 + <div class="col-sm-12"><button class="btn btn-primary btn-sm">Ok</button></div>
  192 + </div>
  193 + </div>
  194 + </div>
  195 + <!-- /.modal-content -->
  196 + </div>
  197 + <!-- /.modal-dialog -->
  198 + </div>
  199 + <!-- /.modal -->
  200 + <!--modal-->
  201 + <!--modal-->
  202 + <div class="modal fade bs-example-modal-sm text-left" tabindex="-1" role="dialog" id="mymodal1">
  203 + <div class="modal-dialog modal-sm" role="document">
  204 + <div class="modal-content">
  205 + <div class="modal-header annotation-modal-header ui-draggable-handle">
  206 + <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
  207 + <h4 class="modal-title" id="">Alert</h4>
  208 + </div>
  209 + <div class="modal-body">
  210 + <h5>Subscription type is required.</h5>
  211 + </div>
  212 + <div class="modal-footer">
  213 + <div class="row">
  214 + <div class="col-sm-12"><button class="btn btn-primary btn-sm">Ok</button></div>
  215 + </div>
  216 + </div>
  217 + </div>
  218 + <!-- /.modal-content -->
  219 + </div>
  220 + <!-- /.modal-dialog -->
  221 + </div>
  222 + <!-- /.modal -->
  223 + <!--modal-->
  224 + </div>
  225 + </div>
  226 + </div>
  227 + </div>
  228 + </div>
  229 +</div>
  230 +<!-- container -->
  231 +</div>
0 232 \ No newline at end of file
... ...
400-SOURCECODE/Admin/src/app/components/SubscriptionPrice/subscriptionprice.component.ts 0 → 100644
  1 +import { Component, OnInit, AfterViewInit, Input, Output, EventEmitter, OnChanges,
  2 + SimpleChanges, TemplateRef, Pipe, PipeTransform } from '@angular/core';
  3 +import { SubscriptionPriceService } from './subscriptionprice.service';
  4 +import { Router } from '@angular/router';
  5 +import { FormControl, FormBuilder, FormGroup, Validators } from '@angular/forms';
  6 +import { SubscriptionPriceModel } from '../UserEntity/datamodel';
  7 +import { BsDatepickerModule } from 'ngx-bootstrap';
  8 +import { Http, Response } from '@angular/http';
  9 +import { DatePipe } from '@angular/common';
  10 +import { ContenteditableModelDirective } from '../../shared/contenteditabledirective'
  11 +import { BsModalService } from 'ngx-bootstrap/modal';
  12 +import { BsModalRef } from 'ngx-bootstrap/modal/bs-modal-ref.service';
  13 +//import { Global } from '../../Shared/global';
  14 +//import { DBOperation } from 'S';
  15 +//import { Observable } from 'rxjs/Observable';
  16 +
  17 +@Component({
  18 + templateUrl: './subscriptionprice.component.html'
  19 +})
  20 +
  21 +export class SubscriptionPrice implements OnInit {
  22 +
  23 +Mode: string = 'Search';
  24 +subscriptionPrice: SubscriptionPriceModel;
  25 +subscriptionPrices: Array<SubscriptionPriceModel>;
  26 +subscriptionPriceFrm: FormGroup;
  27 +insertSubscriptionPriceFrm: FormGroup;
  28 +checkedRecords: Array<number>;
  29 +error: any;
  30 +alerts: string;
  31 +modalAlerts: string;
  32 +topPos: string = '2000px';
  33 +datePipe: DatePipe = new DatePipe('en-US');
  34 +selectedEditionId: number = 1;
  35 +divClass: string = '';
  36 +modalRef: BsModalRef;
  37 +
  38 +constructor(private subscriptionPriceService: SubscriptionPriceService, private router: Router, private fb: FormBuilder, private modalService: BsModalService) { }
  39 +
  40 + ngOnInit(): void {
  41 + this.divClass = 'col-sm-12';
  42 + this.subscriptionPrice = new SubscriptionPriceModel();
  43 + this.alerts = '';
  44 + this.subscriptionPriceFrm = this.fb.group({
  45 + subscriptionPrices: this.fb.array([])
  46 + });
  47 + this.insertSubscriptionPriceFrm = this.fb.group({
  48 + subscriptionPriceId: [''],
  49 + title: ['', Validators.required],
  50 + price: ['', [Validators.required, Validators.pattern('[0-9.]*')]],
  51 + duration: ['', [Validators.required, Validators.pattern('[0-9]*')]],
  52 + editionId: [''],
  53 + isActive: [false]
  54 + });
  55 + this.SearchSubscriptionPrices(this.selectedEditionId);
  56 + }
  57 +
  58 + public SearchSubscriptionPrices(searchEditionId: number) {
  59 + this.selectedEditionId = searchEditionId;
  60 + this.subscriptionPriceService.GetSubscriptionPrices(
  61 + {
  62 + editionId: this.selectedEditionId,
  63 + })
  64 + .subscribe(x => { this.BindFormFields(x) }, error => this.error = error);
  65 + }
  66 +
  67 + openModal(template: TemplateRef<any>) {
  68 + if(this.checkedRecords.filter(C => C > 0).length == 0) return;
  69 + this.modalRef = this.modalService.show(template);
  70 + }
  71 +
  72 + onChange(Idx: number, Id: number, isChecked: boolean){
  73 + if(isChecked){
  74 + this.checkedRecords[Idx] = Id;
  75 + }
  76 + else{
  77 + this.checkedRecords[Idx] = 0;
  78 + }
  79 + }
  80 +
  81 + AfterDeleteData(data, template) {
  82 + if (data.Status == "false") {
  83 + this.alerts = "<span>Subscription prices delete unsuccessfull</span>";
  84 + } else {
  85 + this.modalAlerts = "<p>Subscription prices deleted successfully</p>";
  86 + this.modalRef = this.modalService.show(template);
  87 + this.SearchSubscriptionPrices(this.selectedEditionId);
  88 + }
  89 + }
  90 +
  91 + AfterInsertData(data, template) {
  92 + if (data.Status == "false") {
  93 + this.alerts = "<span>Subscription price save unsuccessfull</span>";
  94 + } else {
  95 + this.modalAlerts = "<p>Subscription price saved successfully</p>";
  96 + this.modalRef = this.modalService.show(template);
  97 + }
  98 + }
  99 +
  100 + AfterUpdateData(data, template) {
  101 + if (data.Status == "false") {
  102 + this.alerts = "<span>Subscription prices update unsuccessfull</span>\n";
  103 + } else {
  104 + this.modalAlerts = "<p>Subscription prices updated successfully</p>";
  105 + this.modalRef = this.modalService.show(template);
  106 + }
  107 + }
  108 +
  109 + BindFormFields(data){
  110 + this.subscriptionPrices = data;
  111 + this.checkedRecords = new Array<number>(this.subscriptionPrices.length);
  112 + this.subscriptionPriceFrm.setControl('subscriptionPrices', this.fb.array(this.subscriptionPrices));
  113 + }
  114 +
  115 + UpdateSubscriptionPrices(template: TemplateRef<any>){
  116 + console.log(this.subscriptionPriceFrm.value);
  117 + this.alerts = '';
  118 + if(this.alerts == ''){
  119 + var obj = this.subscriptionPriceFrm.controls['subscriptionPrices'].value;
  120 + this.subscriptionPriceService.UpdateSubscriptionPrices(obj).subscribe(
  121 + data => (this.AfterUpdateData(data, template)),
  122 + error => {
  123 + this.error = <any>error;
  124 + this.alerts = "<span>" + this.error + "</span>";
  125 + });
  126 + }
  127 + }
  128 +
  129 + InsertSubscriptionPrice(template: TemplateRef<any>){
  130 + console.log(this.insertSubscriptionPriceFrm.value);
  131 + this.alerts = '';
  132 + if(this.alerts == ''){
  133 + var obj = this.insertSubscriptionPriceFrm.value;
  134 + return this.subscriptionPriceService.InsertSubscriptionPrice(obj)
  135 + .subscribe(
  136 + data => (this.AfterInsertData(data, template)),
  137 + error => {
  138 + this.error = <any>error;
  139 + this.alerts = "<span>" + this.error + "</span>";
  140 + });
  141 + }
  142 + }
  143 +
  144 + DeleteSubscriptionPrices(template: TemplateRef<any>){
  145 + console.log(this.checkedRecords);
  146 + this.alerts = '';
  147 + if(this.alerts == ''){
  148 + var obj = this.checkedRecords.filter(C => C > 0);
  149 + return this.subscriptionPriceService.DeleteSubscriptionPrices(obj)
  150 + .subscribe(
  151 + data => (this.AfterDeleteData(data, template)),
  152 + error => {
  153 + this.error = <any>error;
  154 + this.alerts = "<span>" + this.error + "</span>";
  155 + });
  156 + }
  157 + }
  158 +
  159 + AddSubscriptionPrice(){
  160 + this.Mode = 'Add';
  161 + this.topPos = '100px';
  162 + this.divClass = 'col-sm-10 col-sm-offset-1 col-md-8 col-md-offset-2 col-lg-6 col-lg-offset-3';
  163 + this.insertSubscriptionPriceFrm.reset();
  164 + this.alerts = '';
  165 + this.insertSubscriptionPriceFrm.controls['subscriptionPriceId'].setValue(0);
  166 + this.insertSubscriptionPriceFrm.controls['title'].setValue('');
  167 + this.insertSubscriptionPriceFrm.controls['price'].setValue('');
  168 + this.insertSubscriptionPriceFrm.controls['duration'].setValue('');
  169 + this.insertSubscriptionPriceFrm.controls['editionId'].setValue(this.selectedEditionId);
  170 + this.insertSubscriptionPriceFrm.controls['isActive'].setValue(false);
  171 + }
  172 +
  173 + CancelAdd(){
  174 + this.Mode = 'Search';
  175 + this.topPos = '2000px';
  176 + this.divClass = 'col-sm-12';
  177 + this.insertSubscriptionPriceFrm.reset();
  178 + this.alerts = '';
  179 + this.SearchSubscriptionPrices(this.selectedEditionId);
  180 + }
  181 +
  182 +}
... ...
400-SOURCECODE/Admin/src/app/components/SubscriptionPrice/subscriptionprice.service.ts 0 → 100644
  1 +import { Injectable, Inject } from '@angular/core';
  2 +//import { HttpClient, HttpParams, HttpRequest} from "@angular/common/http";
  3 +import { Http, Response, Headers, RequestOptions, HttpModule } from '@angular/http';
  4 +import 'rxjs/add/operator/map';
  5 +import 'rxjs/add/operator/catch';
  6 +import 'rxjs/add/observable/throw';
  7 +import 'rxjs/add/operator/do';
  8 +import { Observable } from 'rxjs/Observable';
  9 +import { GlobalService } from '../../Shared/global';
  10 +
  11 +@Injectable()
  12 +export class SubscriptionPriceService {
  13 +
  14 + constructor(private http: Http, private commonService: GlobalService ) { }
  15 +
  16 +
  17 + GetSubscriptionPrices(obj: any) {
  18 + return this.http.get(this.commonService.SubscriptionBaseUrl + "/GetSubscriptionPrices?editionId="
  19 + + obj.editionId)
  20 + .map(this.extractData)
  21 + .catch((res: Response) => this.handleError(res));
  22 + }
  23 +
  24 + InsertSubscriptionPrice(obj: any) {
  25 + //let options = new RequestOptions({ headers: this.headers });
  26 + var jsonData = {'id': obj.subscriptionPriceId, 'title': obj.title, 'price': obj.price, 'duration': obj.duration, 'editionId': obj.editionId, 'isActive': obj.isActive };
  27 + console.log(obj);
  28 + var headers = new Headers({
  29 + 'Content-Type': 'application/json'
  30 + });
  31 + return this.http.post(this.commonService.SubscriptionBaseUrl + "/InsertSubscriptionPrice",
  32 + JSON.stringify(jsonData), {headers: headers})
  33 + .map(this.extractData)
  34 + .catch((res: Response) => this.handleError(res));
  35 + }
  36 +
  37 + UpdateSubscriptionPrices(obj: any) {
  38 + //let options = new RequestOptions({ headers: this.headers });
  39 + var jsonData = { obj };
  40 + console.log(obj);
  41 + var headers = new Headers({
  42 + 'Content-Type': 'application/json'
  43 + });
  44 + return this.http.post(this.commonService.SubscriptionBaseUrl + "/UpdateSubscriptionPrices",
  45 + JSON.stringify(jsonData), {headers: headers})
  46 + .map(this.extractData)
  47 + .catch((res: Response) => this.handleError(res));
  48 + }
  49 +
  50 + DeleteSubscriptionPrices(obj: any) {
  51 + //let options = new RequestOptions({ headers: this.headers });
  52 + var subscriptionPriceIds = obj;
  53 + console.log(subscriptionPriceIds);
  54 + var headers = new Headers({
  55 + 'Content-Type': 'application/json'
  56 + });
  57 + return this.http.post(this.commonService.SubscriptionBaseUrl + "/DeleteSubscriptionPrices",
  58 + subscriptionPriceIds, {headers: headers})
  59 + .map(this.extractData)
  60 + .catch((res: Response) => this.handleError(res));
  61 + }
  62 +
  63 + extractData(res: Response) {
  64 + //debugger;
  65 + let body = res.json();
  66 + return body;
  67 + }
  68 +
  69 + handleError(error: any) {
  70 + // In a real world app, we might use a remote logging infrastructure
  71 + // We'd also dig deeper into the error to get a better message
  72 + let errMsg = (error.message) ? error.message :
  73 + error.status ? `${error.status} - ${error.statusText}` : 'Server error';
  74 + console.error(errMsg); // log to console instead
  75 + return Observable.throw(errMsg);
  76 + }
  77 +
  78 +
  79 +}
... ...