UNPKG

@stratusjs/idx

Version:

AngularJS idx/property Service and Components bundle to be used as an add on to StratusJS

182 lines (180 loc) 10.6 kB
System.register(["./disclaimer.component.less", "lodash", "@stratusjs/runtime/stratus", "@stratusjs/core/misc", "moment"], function (exports_1, context_1) { "use strict"; var lodash_1, stratus_1, misc_1, moment_1, packageName, moduleName, componentName, localDistStyle; var __moduleName = context_1 && context_1.id; return { setters: [ function (_1) { }, function (lodash_1_1) { lodash_1 = lodash_1_1; }, function (stratus_1_1) { stratus_1 = stratus_1_1; }, function (misc_1_1) { misc_1 = misc_1_1; }, function (moment_1_1) { moment_1 = moment_1_1; } ], execute: function () { packageName = 'idx'; moduleName = 'disclaimer'; componentName = 'disclaimer'; localDistStyle = `${stratus_1.Stratus.BaseUrl}${stratus_1.Stratus.DeploymentPath}@stratusjs/${packageName}/dist/${packageName}.bundle.min.css`; stratus_1.Stratus.Components.IdxDisclaimer = { bindings: { elementId: '@', initNow: '=', service: '@', type: '@', hideOnDuplicate: '@', modificationTimestamp: '=', }, controller($attrs, $sce, $scope, Idx) { $scope.uid = misc_1.safeUniqueId(packageName, moduleName, componentName); stratus_1.Stratus.Instances[$scope.uid] = $scope; $scope.elementId = $attrs.elementId || $scope.uid; $scope.initialized = false; $scope.onWatchers = []; $scope.service = $attrs.service && misc_1.isJSON($attrs.service) ? JSON.parse($attrs.service) : []; $scope.idxService = []; $scope.type = $attrs.type ? JSON.parse($attrs.type) : 'Property'; $scope.alwaysShow = typeof $attrs.hideOnDuplicate === 'undefined'; stratus_1.Stratus.Internals.CssLoader(localDistStyle).then(); let mlsVariables; const init = async () => { Idx.registerDisclaimerInstance($scope.elementId, $scope); Idx.on('Idx', 'sessionInit', () => { if (!$scope.initialized) { $scope.processMLSDisclaimer(); $scope.initialized = true; } Idx.on('Idx', 'fetchTimeUpdate', (_scope, _serviceId, _modelName, _fetchTime) => { $scope.processMLSDisclaimer(true); }); }); Idx.on('Idx', 'sessionRefresh', () => { $scope.processMLSDisclaimer(true); $scope.initialized = true; }); $scope.$watch('$ctrl.hideOnDuplicate', (hideOnDuplicate) => { if (typeof $attrs.hideOnDuplicate !== 'undefined') { $scope.alwaysShow = false; if (hideOnDuplicate !== true) { $scope.hideOnDuplicate = $attrs.hideOnDuplicate ? (lodash_1.isString($attrs.hideOnDuplicate) && misc_1.isJSON($attrs.hideOnDuplicate) ? JSON.parse($attrs.hideOnDuplicate) : false) : false; } else { $scope.hideOnDuplicate = hideOnDuplicate || false; } $scope.$applyAsync(() => { $scope.hideMe = false; if ($scope.hideOnDuplicate) { const instances = Idx.getDisclaimerInstance(); Object.keys(instances).forEach((elementId) => { if (elementId !== $scope.elementId && instances[elementId].alwaysShow === true && (instances[elementId].modificationTimestamp === null || lodash_1.isUndefined(instances[elementId].modificationTimestamp))) { $scope.hideMe = true; } }); } }); } }); Idx.emit('init', $scope); }; this.$onInit = () => { $scope.Idx = Idx; let initNow = true; if (Object.prototype.hasOwnProperty.call($attrs.$attr, 'initNow')) { initNow = misc_1.isJSON($attrs.initNow) ? JSON.parse($attrs.initNow) : false; } const stopWatchingService = $scope.$watch('$ctrl.service', (service) => { $scope.service = lodash_1.isString(service) && misc_1.isJSON(service) ? JSON.parse(service) : []; $scope.processMLSDisclaimer(true); $scope.$applyAsync(); stopWatchingService(); }); if (initNow) { init().then(); return; } const stopWatchingInitNow = $scope.$watch('$ctrl.initNow', (initNowCtrl) => { if (initNowCtrl !== true) { return; } if (!$scope.initialized) { init().then(); } stopWatchingInitNow(); }); }; $scope.getMLSVariables = (reset) => { if (!mlsVariables || Object.keys(mlsVariables).length === 0 || reset) { mlsVariables = []; let mlsServicesRequested = null; if ($scope.service && (lodash_1.isNumber($scope.service) || !lodash_1.isEmpty($scope.service))) { if (!lodash_1.isArray($scope.service)) { $scope.service = [$scope.service]; } mlsServicesRequested = $scope.service; } Idx.getMLSVariables(mlsServicesRequested).forEach((service) => { mlsVariables[service.id] = service; }); } return Object.values(mlsVariables); }; $scope.processMLSDisclaimer = (reset) => { const services = $scope.getMLSVariables(reset); $scope.idxService = []; let disclaimerComplete = ''; services.forEach(service => { let singleDisclaimer = ''; if (service.fetchTime[$scope.type]) { singleDisclaimer += `Last checked ${moment_1.default(service.fetchTime[$scope.type]).format('M/D/YY h:mm a')}. `; } else if (Idx.getLastSessionTime()) { singleDisclaimer += `Last checked ${moment_1.default(Idx.getLastSessionTime()).format('M/D/YY')}. `; } if ($scope.modificationTimestamp) { singleDisclaimer += `Listing last updated ${moment_1.default($scope.modificationTimestamp).format('M/D/YY h:mm a')}. `; } singleDisclaimer += service.disclaimer; if (disclaimerComplete) { disclaimerComplete += '<br>'; } disclaimerComplete += singleDisclaimer; const cleanService = service; cleanService.disclaimerString = singleDisclaimer; cleanService.disclaimerHTML = $sce.trustAsHtml(singleDisclaimer); $scope.idxService.push(cleanService); }); }; $scope.on = (emitterName, callback) => Idx.on($scope.elementId, emitterName, callback); $scope.remove = () => { $scope.onWatchers.forEach(killOnWatcher => killOnWatcher()); }; }, template: '<div id="{{::elementId}}" class="disclaimer-outer-container" data-ng-cloak data-ng-show="idxService.length > 0 && !hideMe" role="contentinfo" aria-label="IDX Disclaimers">' + '<div class="disclaimer-container" data-ng-repeat="service in idxService" data-ng-bind-html="service.disclaimerHTML"></div>' + '<div class="mls-logos-section" aria-label="MLS Logos">' + '<div class="mls-logos-container" data-ng-repeat="service in idxService">' + '<img class="mls-service-logo" alt="{{service.name}} MLS Brand Logo" data-ng-show="service.logo.default" aria-label="{{service.name}}" data-ng-src="{{service.logo.medium || service.logo.default}}">' + '<img class="mls-service-logo" alt="{{service.name}} MLS supplementary Logo" data-ng-if="service.mandatoryLogo && service.mandatoryLogo.length > 0" data-ng-repeat="mandatoryLogo in service.mandatoryLogo" aria-label="{{service.name}} supplementary" data-ng-src="{{mandatoryLogo}}">' + '</div>' + '</div>' + '</div>' }; } }; }); //# sourceMappingURL=disclaimer.component.js.map