Skip to content

Instantly share code, notes, and snippets.

@texirv0203
Created September 9, 2017 21:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save texirv0203/9719b28df9c49b27e2e357a8afd85aa6 to your computer and use it in GitHub Desktop.
Save texirv0203/9719b28df9c49b27e2e357a8afd85aa6 to your computer and use it in GitHub Desktop.
import {Component,AfterViewInit, ElementRef, Inject,Input,EventEmitter,NgZone,OnInit, ViewChild, Pipe} from '@angular/core';
import {Router, ActivatedRoute} from '@angular/router';
import {NetworkCarousel} from '../shared/content/network-carousel';
import { SPORTService } from '../../services/SPORT.service';
// import {ProgressCircle} from '../shared/progress/progress-circle';
import {validationService} from '../shared/content/validation';
import {tigerLeftSliderComponent} from './tiger-left-slider';
import {KendoGridComponent} from '../grid/grid.component';
import {recentPinnedHistoryService} from '../shared/content/recent-pinned-history';
import {Pager} from '../common/pager';
import {parrotViewDetails} from '../parrots/tiger-sweet-viewdetails';
import {parrotCurrents} from '../parrots/parrot-Currents';
@Component({
selector: 'tiger-sweet-start',
templatecode: "./app/components/parrots/tiger-sweet-start.html",
providers: [Pager,parrotViewDetails,parrotCurrents]
})
export class tigersweetstart implements AfterViewInit {
public startId = "";
public startName = "";
public brainId = "";
public brainName = "";
public PaymentId = "";
public InvoiceNo = "";
public WBSC = "";
public paymentDueDate = "";
public brainTypes=[];
public vendorList : any;
public isTileView : boolean;
public isGridView : boolean;
public distributors =[{"distributorID":"","distributorName":""}];
public showEntriesValue;
public kendoGridDatasource = [];
private selectedoptions;
public selectedCurrentId;
// paged items
    pagedItems: any[];
    brainSelectedPageSize : number;
@Input() public inputNetworkCarousel : NetworkCarousel;
@ViewChild(KendoGridComponent) public gridkendo: KendoGridComponent;
@ViewChild(tigerLeftSliderComponent) public tigerLeftSlider: tigerLeftSliderComponent;
@ViewChild(parrotCurrents) public parrotCurrents: parrotCurrents;
constructor(public ngZone : NgZone,
private recentPinnedHistory: recentPinnedHistoryService, // <== added
public elementRef: ElementRef,private router: Router,
public SPORTService : SPORTService,
public validation : validationService, public pager : Pager ,public parrotViewDetails:parrotViewDetails){
}
ngAfterViewInit() {
// child is set
this.intializeKendoGridstart(this.gridkendo);
}
ngOnInit() {
let that=this;
this.ngZone.run(() => {
that.isGridView = true;
that.isTileView = false;
});
$('#tileView').addClass('disabledIcon');
$('#listView').removeClass('disabledIcon');
$(".datepicker").kendoDatePicker();
let navHeaderHeight = $('.navHeaderBox').outerHeight();
$('.breadCrumbBox').css('top', navHeaderHeight+'px');
$('.km-switchLabel:not(.switchbtn)').toggleClass('fontDisabled');
$(Current).ready(function(){
let winheight = ($(window).innerHeight())-174;
let winWidth = $(window).innerWidth();
$( ".tab-pane" ).css({'height':winheight+'px','overflow-y':'auto'});
$(".showHideIcon").click(function(){
$(".showHideInputBox").slideToggle();
$('.showHideIcon').toggleClass('toggleShow');
});
$(".showHideFavBtn").click(function(){
let showHideTopPos = $('.breadCrumbBox').outerHeight() + $('.navHeaderBox').outerHeight();
$('.showHideFav').css({ 'top': (showHideTopPos - 6) + 'px' });
var winWidth = $(window).innerWidth();
if (winWidth < 1025) {
$('.showHideFav').toggleClass('toggleShow');
} else {
$('.showHideFav').toggleClass('shoHideMenuActive');
}
$('.slideShrinkBox').toggleClass('active');
});
let curDocHeight = $(Current).outerHeight();
let navHeaderHeight = $('.navHeaderBox').outerHeight();
let breadCrumbHeight = $('.breadCrumbBox').outerHeight();
let kGridGroupingHeaderHeight = $('.k-grouping-header').outerHeight();
let kGridHeaderHeight = $('.k-grid-header').outerHeight();
$('.showHideFav .favHistoryBox').css(
{
'min-height': (curDocHeight - (navHeaderHeight + breadCrumbHeight + kGridGroupingHeaderHeight + kGridHeaderHeight))+'px'
}
);
let windowHeight = $(window).outerHeight(true);
kGridHeaderHeight = $(".k-grid-header").outerHeight(true);
let kGridFooterHeight = $(".k-grid-pager").outerHeight(true);
let kGridGroupingHeight = $(".k-grouping-header").outerHeight(true);
let scrolledHeight = $(Current).scrollTop();
});
$(Current).on("click", "#searchNameRequiredBtn", function() {
$('.searchNameRequiredPopup').hide();
});
this.loadView(this);
}
noseBind(startVal:any)
{
$("#nose_"+startVal.id).kendonoseMenu({
target:"#span_"+startVal.id,
showOn: "click"
});
}
loadView(that):any{
let data={};
that.SPORTService.getResponse("parrots/v1/listOflink?type=DB",'get',data)
.subscribe(data => {
if(JSON.stringify(data) !== JSON.stringify({})){
//this.progress.requestEnd();
if(data.vendors) {
that.vendorList = data.vendors.sort(function(a, b){
let nameA=a.name.toLowerCase(); let nameB=b.name.toLowerCase();
if (nameA < nameB) //sort string ascending
return -1
if (nameA > nameB)
return 1
return 0 //default return value (no sorting)
});
}
that.brainTypes = data.brainType;
if(data.favorites) {
that.tigerLeftSlider.savedSearchList = data.favorites.filter(item => (item.type === "start" && item.category === "S"));
}
} else
console.log('No data returned in Response from "parrots/v1/listOflink?type=DB"');
},
err => { /*this.progress.requestEnd();*/ }
);
that.SPORTService.getResponse("startsaggregator/v1/listOflink?type=search",'get',data)
.subscribe(data => {
if(JSON.stringify(data) !== JSON.stringify({})){
//this.progress.requestEnd();
that.distributors= data.distributors;
} else
console.log('No data returned in Response from "startsaggregator/v1/listOflink?type=search"');
},
err => { /*this.progress.requestEnd();*/ }
);
$("#startSearchBtn").focus();
}
searchstart():void{
let that = this;
let startSearchPostParams = that.prepareSearchObjectParams("");
that.gridClearFilter();
//this.progress.requestStart();
that.SPORTService.getResponse("parrots/v1/parrots", 'post', startSearchPostParams)
.subscribe(data => {
//this.progress.requestEnd();
that.populateGrid(data);
that.kendoGridDatasource = data.sweetDetails; // dataset
this.setTilePage(1);
//this.progress.requestEnd();
},
err => { /*this.progress.requestEnd();*/ }
);
}
populateGrid(data)
{
let that=this;
that.gridkendo.reloadDataSource(data.sweetDetails);
}
gridClearFilter()
{
let that=this;
let grid1= this.gridkendo.getGrid();
grid1.setOptions({
autoBind:false,
columns:that.kendocommand.columns
});
this.gridkendo.setscroll();
var clearFilter = this.gridkendo._dataSource.filter()?this.gridkendo._dataSource.filter({}):"";
clearFilter = this.gridkendo._dataSource.data()?this.gridkendo._dataSource.data([]):"";
}
/* start SEARCH STARTS HERE */
private kendocommand = {
edit:{createAt: "bottom"},
autoBind:false,
group:true,
reorder:true,
resize:true,
sort:true,
filter:{mode:"row"},
pager:{messages: {display: "Showing {0} to {1} of {2} entries"}},
model:{},
columns:[],
aggregate:[],
pagesize: 5,
//getComponentcode:"start.json",
//getComponentcode:"starts/v1/starts",
postComponentcode:"parrots/v1/parrots",
searchFields:[],
noseMenuId:"nose-menuparrotSearch",
excelfileUidName:"startSearchResult",
isRowClick:true,
disableFreeze:true,
excelFileName:{
fileName: "",
allPages: true
}
}
intializeKendoGridstart(kendo : KendoGridComponent) : void {
this.kendocommand.model={
id: "id",
data: "sweetDetails",
fields: {
id: { type: "number", editable: false, nullable: true, },
name: {type: "string", editable: false, nullable: true},
wbseCode: { type: "string",editable: false, nullable: true },
brainsCount: { type: "number", editable: false, nullable: true },
totalCost: { type: "string", editable: false, nullable: true },
totalPayment: { type: "string", editable: false, nullable: true },
totalAmortAmount: { type: "string", editable: false, nullable: true}
}
};
this.kendocommand.aggregate = [
{ field: "id", aggregate: "count" },
{ field: "name", aggregate: "count" },
{ field: "wbseCode", aggregate: "count" },
{ field: "brainsCount", aggregate: "count" },
{ field: "totalCost", aggregate: "count" },
{ field: "totalPayment", aggregate: "count" },
{ field: "totalAmortAmount", aggregate: "count" }
];
this.kendocommand.columns=[
{field:"noseRow",groupable:false,locked: true, editable:false, lockable: false, resizable:false, template: '<span class="noseMenuRow"></span>', width: 25 },
{field: "id",brain: "start#",width: 100, aggregates: ["count"],groupHeaderTemplate: "start: #= value # (#= count# item(s))",resizable:false, filterable:kendo.getAutoFilter("eq") },
{field: "name",brain: "NAME", width: 225, aggregates: ["count"],groupHeaderTemplate: "start Name: #= value # (#= count# item(s))",filterable:kendo.getAutoFilter("contains") },
{field: "wbseCode",brain: "WBSE",width: 150, aggregates: ["count"],groupHeaderTemplate: "WBSE: #= value # (#= count# item(s))", filterable:kendo.getAutoFilter("eq") },
{field: "brainsCount",brain: "brainS", width: 80, aggregates: ["count"],groupHeaderTemplate: "brains Count: #= value # (#= count# item(s))",filterable:kendo.getAutoFilter("eq") },
{field: "totalCost",brain: "COST", width: 150,aggregates: ["count"],groupHeaderTemplate: "Total Cost: #= value # (#= count# item(s))",filterable:kendo.getAutoFilter("eq") },
{field: "totalPayment",brain: "PAYMENT", width: 150, aggregates: ["count"],groupHeaderTemplate: "Total Payment: #= value # (#= count# item(s))",filterable:kendo.getAutoFilter("eq") },
{field: "totalAmortAmount",brain:"AMORTIZATIONS", width: 150, aggregates: ["count"],groupHeaderTemplate: "Total Amort Amount: #= value # (#= count# item(s))",filterable:kendo.getAutoFilter("eq") }
];
this.validation.onlyNumbers("#startId");
}
startSearchExport():void{
this.gridkendo.exportExcel();
}
clearstart():void{
$('#OwnerOnly').prop('checked', false);
$('#VendorListDropdownstart').val('');
$('#brainType').val('');
$('#distributor').val('');
this.ngZone.run(() => {
this.startId = "";
this.startName = "";
this.brainId = "";
this.brainName = "";
this.PaymentId = "";
this.InvoiceNo = "";
this.WBSC = "";
this.paymentDueDate = "";
});
this.gridkendo.gridClear();
let arrayImg=[];
let temObj={};
temObj['networkNo']=1;
temObj['image']="./assets/images/networks/1.png";
arrayImg.push(temObj);
this.inputNetworkCarousel.selectedNetworkImg(arrayImg);
this.kendoGridDatasource = []; // dataset
this.setTilePage(1);
this.pager.totalPages=1;
}
gridPagesizestart(value):void{
let that = this;
that.showEntriesValue = value;
if(value == "All")
that.gridkendo.gridPageSizeAll();
else
that.gridkendo.gridPageSizeChangeAll(value);
//this.gridkendo.reloadDataSource(this.kendoGridDatasource);
}
prepareSearchObjectParams(checkingSourceBtn):any {
let networksId:any=[];
networksId=this.inputNetworkCarousel.getselectedNetworkID();
if(networksId.length==0){
networksId=this.inputNetworkCarousel.getNetworkIdList();
}
return {
"type":"start_SEARCH",
// savedsearch saves ALL the link selected. However Search API is accepting only ONE value.
// ONCE it allows multi-value we should CHANGE the below LINE.
"networkNo": (networksId[0] !== undefined) ? (checkingSourceBtn == "" ? networksId[0] : networksId) : 1,
"startNo": $('#startId').val() !== undefined ? $('#startId').val() : "",
"startName": $('#startName').val() !== undefined ? $('#startName').val() : "",
"brainNo": $('#brainId').val() !== undefined ? $('#brainId').val() : "",
"brainName": $('#brainName').val() !== undefined ? $('#brainName').val() : "",
"brainType": ($('#brainType').val() !== undefined && $('#brainType').val() !== null) ? $('#brainType').val() : "",
"distributor": ($('#distributor').val() !== undefined && $('#distributor').val() !== null) ? $('#distributor').val() : "",
"vendor": ($('#VendorListDropdownstart').val() !== undefined && $('#VendorListDropdownstart').val() !== null) ? $('#VendorListDropdownstart').val() : "",
"paymentNo": $('#PaymentId').val() !== undefined ? $('#PaymentId').val() : "",
"invoiceNo": $('#InvoiceNo').val() !== undefined ? $('#InvoiceNo').val() : "",
"wbseCode": $('#WBSC').val() !== undefined ? $('#WBSC').val() : "",
"paymentDueDate": $('#paymentDueDate').val() !== undefined ? this.getDateformate($('#paymentDueDate').val()) : "",
"isOwner": $('#OwnerOnly').prop('checked') ? "true" : "false"
};
//this.gridkendo.gridSearch(this.kendocommand.postComponentcode,this.startSearchPost,this.HTTPType);
}
rowDotMenuClick(link:any):void {
let that = this;
if(link.selectedMenuItem=='View Details'){
that.parrotViewDetails.openPopup(link.Selectedrow,'start');
}
else if(link.selectedMenuItem=='Manage Currents'){
that.bear(link.Selectedrow, 'start');
}
}
menuClick(link:any,menuItemName:string,event):void {
let that = this;
if(menuItemName=='View Details'){
that.parrotViewDetails.openPopup(link,'start');
}
if(menuItemName=='Manage Currents'){
that.bear(link, 'start');
}
}
tileViewClicked(): void{
$('#listView').addClass('disabledIcon');
$('#tileView').removeClass('disabledIcon');
this.ngZone.run(() => {
this.isGridView = false;
this.isTileView = true;
});
}
listViewClicked(): void{
let that = this;
//let startSearchPostParams = that.prepareSearchObjectParams("");
$('#tileView').addClass('disabledIcon');
$('#listView').removeClass('disabledIcon');
that.ngZone.run(() => {
that.isGridView = true;
that.isTileView = false;
});
this.refreshGrid(0,0);
//that.gridPagesizestart($('#pagesize').val());
}
refreshGrid(milliseconds: number, count: number): Promise<number> {
let that=this;
return new Promise<number>(resolve => {
setTimeout(() => {
let grid1= this.gridkendo.getGrid();
grid1.setOptions({
autoBind:false,
columns:that.kendocommand.columns
});
this.gridkendo.setscroll();
this.gridkendo.Refresh();
resolve(count);
}, milliseconds);
});
}
setTilePage(page: number) {
if (page < 1 || page > this.pager.totalPages) {
return;
}
// get pager object from service
this.pager.currentPage=page;
this.brainSelectedPageSize=this.pager.pageSize;
if($('#pagetilesize').val())
{
this.pager.pageSize=$('#pagetilesize').val();
this.brainSelectedPageSize=$('#pagetilesize').val();
}
else
{
this.pager.pageSize=8;
$('#pagetilesize').val(this.pager.pageSize);
}
this.pager.getTilePager(this.kendoGridDatasource.length);
// get current page of items
this.pagedItems = this.kendoGridDatasource.slice(this.pager.startIndex, this.pager.endIndex + 1);
//console.log('paged Items length = ' + this.pagedItems.length);
}
getSelectedPageSize()
{
return this.brainSelectedPageSize;
}
saveSearch() : void
{
let that = this;
if($('#saveSearchName').val().trim().length == 0) {
$('.searchNameRequiredPopup').show();
return;
}
let saveSearchName = $('#saveSearchName').val();
let startSearchPostParams = this.prepareSearchObjectParams("SaveSearch");
let saveSearchParams = {
"searchQueryText": JSON.stringify(startSearchPostParams),
"type": "start",
"desc": saveSearchName, //"start Saved Search Criteria-1",
"category": "S",
"moduleId": 1,
"screenId": 1
}
let response;
this.SPORTService.getResponse("anotherlink", 'post', saveSearchParams)
.subscribe(response => {
if(response.code == 'S500'){
let newItemSaved = {
"searchQueryText": JSON.stringify(startSearchPostParams),
"type": "start",
"desc": saveSearchName, //"start Saved Search Criteria-1",
"category": "S",
"id" : response.id[0]
}
that.ngZone.run(() => {
that.tigerLeftSlider.savedSearchList.push(newItemSaved);
});
}
},
err => { /*this.progress.requestEnd();*/ }
);
$('#saveSearchName').val(''); // clear
}
getSaveEvent(retrieveSaveData:any)
{
let that=this;
let getData=JSON.parse(that.tigerLeftSlider.savedSearchList.filter(item => item.id === retrieveSaveData)[0].searchQueryText);
this.setSavedSearchValue(getData);
}
getCurrentEvent(getCurrentData:any)
{
var index = this.kendoGridDatasource.findIndex(x=>x.id === this.selectedCurrentId)
if(this.kendoGridDatasource[index].docsCount!=getCurrentData)
{
this.kendoGridDatasource[index].docsCount=getCurrentData;
this.setTilePage(this.pager.currentPage);
}
$(".compassBox").css("overflow-y","scroll");
$(".slideShrinkBox").css("overflow-y","scroll");
//$(window).scrollTop();
// $(Current).scrollTop();
// $(Current).css("background", "red");
// $(".formIputsBox").animate({
// scrollTop: 5,
// })
}
getDateformate(dateValue): any {
if (dateValue != null && dateValue != "") {
return kendo.toString(new Date(dateValue), 'yyyy-MM-dd');
}
else { return ""; }
}
setSavedSearchValue(savedData:any)
{
$('#startName').val(savedData.startName);
$('#startId').val(savedData.startNo);
$('#brainId').val(savedData.brainId);
$('#brainName').val(savedData.brainName);
$('#brainType').val(savedData.brainType);
$('#distributor').val(savedData.distributor);
$('#VendorListDropdownstart').val(savedData.vendor);
$('#PaymentId').val(savedData.PaymentId);
$('#InvoiceNo').val(savedData.InvoiceNo);
$('#WBSC').val(savedData.wbseCode);
$('#paymentDueDate').val(savedData.paymentDueDate);
$("#OwnerOnly").prop( "checked",savedData.isOwner);
let arrayImg=[];
for(let j=0;j<savedData.networkNo.length;j++){
let temObj={};
temObj['networkNo']=savedData.networkNo[j];
temObj['image']="./assets/images/networks/"+savedData.networkNo[j]+".png"
arrayImg.push(temObj);
}
this.inputNetworkCarousel.selectedNetworkImg(arrayImg);
this.clearGrid();
this.kendoGridDatasource = []; // dataset
this.setTilePage(1);
this.pager.totalPages=1;
}
clearGrid()
{
this.gridkendo.gridClear();
}
private gridTemplate(options: any, fieldName: any, mandatory: any) {
let value = options[fieldName];
if (options[fieldName] == null || options[fieldName] == undefined) {
//console.log("fieldName : "+fieldName);
value = "";
options[fieldName] = " ";
}
if (mandatory) {
value = "<i>" + value + "</i>"
}
options[fieldName + "FilterRowId"] = options[fieldName];
return value;
}
bear(link, source): void {
console.log("bear");
//let columns;
let brain;
let excelFileName;
let startNo;
let code;
let netNo;
let mainId;
let that = this;
brain = "CurrentS";
excelFileName = "ViewkokoExport";
this.selectedCurrentId=link.id;
//code = "startsaggregator/v1/start/koko/123/456";
//code = "someLink{id}";
//CurrentName
//CurrentType
code = "someLink" + link.id;
mainId = link.id;
let columns = [{
field: 'noseRow',
editable: false,
template: '<span class="noseMenuRow" id="noseMenuRow"></span>',
width: 25,
locked: false
}, {
field: "CurrentId",
width: 25,
brain: " ",
sortable: false,
/*template:"<span class='CurrentIcon displayInlineBlock'></span>"/*,*/
// template: function name(model) {
// return that.ImageType(model);
// },
template: function name(model, CurrentName) {
return "testing" + that.parrotCurrents.ImageType(model);
},
editor: function(container, model) {
//that.parrotCurrents.docTemplateEditor(container, model, that,this.selectedoptions);
}
}, {
field: "CurrentName",
filterable: that.gridkendo.getAutoFilterName("eq", "CurrentName"),
headerAttributes: {
class: "multiCheckboxFilterEnabled"
},
brain: "File Name",
width: 200,
editable: false,
// template: function CurrentName(options){
// return that.gridTemplate(options,"CurrentName",false);
// }
template: "<a onclick=\"window.open('#= CurrentName#', 'popup', 'width=800,height=600,scrollbars=yes,resizable=no')\">#= CurrentName.substring(CurrentName.lastIndexOf('/')+1) #</a>"
//template: "<a onclick=\"window.open('#= CurrentName#', 'popup', 'width=800,height=600,scrollbars=yes,resizable=no')\">#=/assets/js/actualkoko.json</a>"
//template: "<a href='file:///#= CurrentName #' target='_blank'>#= CurrentName.substring(CurrentName.lastIndexOf('/')+1) #</a>"
}, {
field: "CurrentType",
hidden: true
}, {
field: "CurrentData",
hidden: true
}, {
field: "notes",
hidden: true
}, {
field: "notesId",
hidden: true
}, {
field: "elfDocID",
hidden: true
}, {
field: "code",
hidden: true
}, {
field: "date",
filterable: that.gridkendo.getAutoFilterName("contains", "date"),
headerAttributes: {
class: "multiCheckboxFilterEnabled"
},
brain: "Added Date",
width: 200,
editable: false,
template: function date(options) {
return that.gridTemplate(options, "date", false);
}
}, {
field: "addedByName",
filterable: that.gridkendo.getAutoFilterName("contains", "addedByName"),
headerAttributes: {
class: "multiCheckboxFilterEnabled"
},
brain: "Added By",
width: 200,
editable: false,
template: function addedByName(options) {
return that.gridTemplate(options, "addedByName", false);
}
}, {
field: "userID",
hidden: true
}, {
field: "operationType",
hidden: true
}
];
let data = {
"code": code,
"columns": columns,
"brain": brain,
"excelFileName": excelFileName,
"mainId": mainId
};
this.parrotCurrents.openPopup(data,'start');
// console.log("data--->" + JSON.stringify(data));
}
distributorChange(distributorsvalue:any):any{
$("#startSearchBtn").focus();
}
brainTypeChange(start:any):any{
$("#startSearchBtn").focus();
}
vendorListChange(start:any):any{
$("#startSearchBtn").focus();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment