daily pastebin goal
68%
SHARE
TWEET

Untitled

a guest Dec 10th, 2018 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import * as ko from 'knockout';
  2.     import styles from './Search.module.scss';
  3.     import { ISearchWebPartProps } from './SearchWebPart';
  4.     import pnp, { SearchResults, Web, SearchResult, SortDirection } from 'sp-pnp-js';
  5.     import { QueryBuilder } from './Support/QueryBuilder';
  6.     import { SearchParameters } from './Entities/SearchParameters';
  7.     import { CommonFunctions } from './Support/CommonFunctions';
  8.     import { AppConstants } from './Constants/AppConstants';
  9.     import { ListNames } from './Constants/ListNames';
  10.     import { DocumentCategory } from './Entities/DocumentCategory';
  11.     import { ResultTableProperties } from './Entities/ResultTableProperties';
  12.     import { PinnedDocuments } from './Entities/PinnedDocuments';
  13.     import { SPComponentLoader } from '@microsoft/sp-loader';
  14.     import * as $ from "jquery";
  15.     import { Topics } from './Entities/Topics';
  16.     import { PinnedLists } from "./Entities/PinnedLists";
  17.     import { UserPinnedLists } from "./Entities/UserPinnedLists";
  18.     import { ConfigProperties } from "./Entities/ConfigProperties";
  19.     import { ConfigKeys } from "./Constants/ConfigKeys";
  20.     import 'jqueryui';
  21.     require('./es6-promise.auto.min.js');
  22.     let Swal: any = require('./sweetalert2.min.js');
  23.     let moment: any = require('./MyWIMS-I/js/moment.min.js');
  24.  
  25.     require('./MyWIMS-I/css/sweetalert2.min.css');
  26.     require('./SwalStyles.css');
  27.     require('./WimsJS.js');
  28.  
  29.  
  30.  
  31.     export interface ISearchBindingContext extends ISearchWebPartProps {
  32.         shouter: KnockoutSubscribable<{}>;
  33.     }
  34.  
  35.     export default class SearchViewModel {
  36.  
  37.         public resultTablePageSize: KnockoutObservable<number> = ko.observable(50);
  38.         public mmsName: KnockoutObservable<string> = ko.observable("");
  39.         public topicsTermID: KnockoutObservable<string> = ko.observable("");
  40.         public startPageNumber: KnockoutObservable<number> = ko.observable(1);
  41.         public lastPageNumber: KnockoutObservable<number> = ko.observable(1);
  42.         public currentPageNumber: KnockoutObservable<number> = ko.observable(1);
  43.         public pinnedDocumentsCount: KnockoutObservable<number> = ko.observable(0);
  44.         public isPrevEnabled: KnockoutObservable<boolean> = ko.observable(false);
  45.         public isNextEnabled: KnockoutObservable<boolean> = ko.observable(false);
  46.         public selectedCategory: KnockoutObservable<string> = ko.observable('');
  47.         public resultTableDocProperties: KnockoutObservableArray<ResultTableProperties> = ko.observableArray([]);
  48.         public rootCategoryDetails: KnockoutObservableArray<DocumentCategory> = ko.observableArray([]);
  49.         public topicsTerms: KnockoutObservableArray<Topics> = ko.observableArray([]);
  50.         public pinnedsectionDetails: KnockoutObservableArray<PinnedLists> = ko.observableArray([]);
  51.         public selectpinListDetails: KnockoutObservableArray<UserPinnedLists> = ko.observableArray([]);
  52.         public associatedLists: KnockoutObservableArray<string> = ko.observableArray([]);
  53.         public docToUnPin: KnockoutObservable<string> = ko.observable('');
  54.  
  55.         public searchParameters: KnockoutObservable<SearchParameters> = ko.observable(new SearchParameters());
  56.         public openedPinnedList: KnockoutObservable<PinnedLists> = ko.observable(new PinnedLists());
  57.         public isLoading: KnockoutObservable<boolean> = ko.observable(true);
  58.         public isPinnedSectionOpen: KnockoutObservable<boolean> = ko.observable(false);
  59.         public webAbsUrl: string = '';
  60.         public webServRelUrl: string = '';
  61.         public docCategoryDetails: DocumentCategory[] = [];
  62.         private oWeb: Web = undefined;
  63.  
  64.         constructor(bindings: ISearchBindingContext) {
  65.  
  66.             this.webAbsUrl = bindings.webAbsUrl;
  67.             this.webServRelUrl = bindings.webServRelUrl;
  68.             this.isLoading(true);
  69.             this.resultTablePageSize(parseInt(bindings.pageSize));
  70.             this.mmsName(bindings.mmsName);
  71.             this.topicsTermID(bindings.topicsTermID);
  72.             this.oWeb = new Web(bindings.webAbsUrl);
  73.             SPComponentLoader.loadScript(this.webAbsUrl + '/_layouts/15/clienttemplates.js', { globalExportsName: 'jQuery' }).then((jQuery: any): void => {
  74.             });
  75.  
  76.             SPComponentLoader.loadCss(this.webAbsUrl + '/SiteAssets/css/bootstrap.min.css');
  77.             SPComponentLoader.loadCss('https://fonts.googleapis.com/css?family=Poppins:300,400,500,600,700');
  78.             SPComponentLoader.loadScript(this.webAbsUrl + '/SiteAssets/js/jquery-2.2.4.min.js', { globalExportsName: 'jQuery' }).then((jQuery: any): void => {
  79.                 SPComponentLoader.loadScript(this.webAbsUrl + '/SiteAssets/js/jquery-ui.min.js', { globalExportsName: 'jQuery' }).then((jQuery: any): void => {
  80.                     SPComponentLoader.loadScript(this.webAbsUrl + '/SiteAssets/js/bootstrap.min.js', { globalExportsName: 'jQuery' }).then((): void => {
  81.                         SPComponentLoader.loadScript('https://cdnjs.cloudflare.com/ajax/libs/core-js/2.4.1/core.js', { globalExportsName: 'jQuery' }).then((): void => {
  82.                         });
  83.                     });
  84.                 });
  85.             });
  86.  
  87.  
  88.             this.oWeb.currentUser.get().then((_currentUser: any) => {
  89.                 this.currentUserID = _currentUser.Id;
  90.                 this.GetUserPinnedLists();
  91.                 const sessionKey: string = CommonFunctions.GetQueryStringParameter(AppConstants.CONST_Session_Key);
  92.                 const _srchParams: SearchParameters = CommonFunctions.GetSearchParameters(sessionKey);
  93.                 this.searchParameters(_srchParams);            
  94.                 this.InitiateWIMSSearch();          
  95.             });
  96.         }
  97.  
  98.         private GetUserPinnedLists(): void {
  99.             this.pinnedListsDetails = [];
  100.             this.oWeb.lists.getByTitle(ListNames.LIST_User_Specific_Pinned_Lists).items.filter("UserNameId eq " + this.currentUserID).orderBy("PinnedListOrder", true).get().then(_pinnedLists => {
  101.                 if (_pinnedLists && _pinnedLists.length > 0) {
  102.                     for (let i = 0; i < _pinnedLists.length; i++) {
  103.                         this.pinnedListsDetails.push({ ListName: _pinnedLists[i].Title, ListID: _pinnedLists[i].ID, Documents: [], IsExpanded: false, IsSeeMoreVisible: true });
  104.                     }
  105.                 }
  106.                 this.pinnedListsDetails.push({ ListName: AppConstants.CONST_DEFAULT_PinnedList, ListID: 1, Documents: [], IsExpanded: false, IsSeeMoreVisible: true });
  107.             }).catch(e => { this.LogException("GetUserPinnedLists", e); });
  108.         }
  109.  
  110.         private InitiateWIMSSearch(): void {
  111.             this.GetTopicsTerms();
  112.             this.SearchDocuments(1);        
  113.         }
  114.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top