Skip to content

Commit

Permalink
draft a customized version of angular.merge for tile configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
akloeckner committed Nov 16, 2020
1 parent 5bece8b commit d74e070
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"angularjs-gauge": "^2.2.0",
"chart.js": "^2.9.4",
"hls.js": "^0.14.16",
"lodash.mergewith": "^4.6.2",
"node-sass": "^5.0.0"
},
"resolutions": {
Expand Down
14 changes: 12 additions & 2 deletions scripts/controllers/main-utilities.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import angular from 'angular';
import mergeWith from 'lodash.mergewith';
import { TILE_DEFAULTS, TYPES } from '../globals/constants';

export function mergeConfigDefaults (pages) {
Expand Down Expand Up @@ -38,7 +38,17 @@ function mergeTileListDefaults (tiles) {

function mergeTileDefaults (tile) {
if (tile && tile.type in TILE_DEFAULTS) {
return angular.merge({}, TILE_DEFAULTS[tile.type], tile);
return mergeTileConfigs({}, TILE_DEFAULTS[tile.type], tile);
}
return tile;
}

export function mergeTileConfigs (object, ...sources) {
return mergeWith(object, ...sources, mergeTileCustomizer);
}

function mergeTileCustomizer (objValue, srcValue, key) {
if (key === 'classes' && Array.isArray(objValue) && Array.isArray(srcValue)) {
return objValue.concat(srcValue);
}
}
8 changes: 4 additions & 4 deletions scripts/controllers/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import angular from 'angular';
import Hammer from 'hammerjs';
import { mergeConfigDefaults } from './main-utilities';
import { mergeConfigDefaults, mergeTileConfigs } from './main-utilities';
import { App } from '../app';
import { TYPES, FEATURES, HEADER_ITEMS, MENU_POSITIONS, GROUP_ALIGNS, TRANSITIONS, MAPBOX_MAP, YANDEX_MAP, DEFAULT_SLIDER_OPTIONS, DEFAULT_LIGHT_SLIDER_OPTIONS, DEFAULT_VOLUME_SLIDER_OPTIONS, DEFAULT_POPUP_HISTORY, DEFAULT_POPUP_IFRAME, DEFAULT_POPUP_DOOR_ENTRY } from '../globals/constants';
import { debounce, leadZero, supportsFeature, toAbsoluteServerURL } from '../globals/utils';
Expand Down Expand Up @@ -1601,15 +1601,15 @@ App.controller('Main', function ($scope, $timeout, $location, Api) {
};

$scope.openPopupHistory = function (item, entity) {
const layout = cacheInItem(item, '_popupHistory', () => angular.merge(DEFAULT_POPUP_HISTORY(item, entity), {
const layout = cacheInItem(item, '_popupHistory', () => mergeTileConfigs({}, DEFAULT_POPUP_HISTORY(item, entity), {
classes: getItemFieldValue('history.classes', item, entity) || [],
items: [getItemFieldValue('history', item, entity) || {}],
}));
$scope.openPopup(item, entity, layout);
};

$scope.openPopupIframe = function (item, entity) {
const layout = cacheInItem(item, '_popupIframe', () => angular.merge(DEFAULT_POPUP_IFRAME(item, entity), {
const layout = cacheInItem(item, '_popupIframe', () => mergeTileConfigs({}, DEFAULT_POPUP_IFRAME(item, entity), {
classes: getItemFieldValue('iframeClasses', item, entity) || [],
items: [{
customStyles: getItemFieldValue('iframeStyles', item, entity) || {},
Expand All @@ -1619,7 +1619,7 @@ App.controller('Main', function ($scope, $timeout, $location, Api) {
};

$scope.openDoorEntry = function (item, entity) {
const layout = cacheInItem(item, '_popupDoorEntry', () => angular.merge(DEFAULT_POPUP_DOOR_ENTRY(item, entity), {
const layout = cacheInItem(item, '_popupDoorEntry', () => mergeTileConfigs({}, DEFAULT_POPUP_DOOR_ENTRY(item, entity), {
items: [
getItemFieldValue('layout.camera', item, entity) || {},
...(getItemFieldValue('layout.tiles', item, entity) || []),
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3853,6 +3853,11 @@ lodash.memoize@^4.1.2:
resolved "https://registry.yarnpkg.com/lodash.memoize/-/lodash.memoize-4.1.2.tgz#bcc6c49a42a2840ed997f323eada5ecd182e0bfe"
integrity sha1-vMbEmkKihA7Zl/Mj6tpezRguC/4=

lodash.mergewith@^4.6.2:
version "4.6.2"
resolved "https://registry.yarnpkg.com/lodash.mergewith/-/lodash.mergewith-4.6.2.tgz#617121f89ac55f59047c7aec1ccd6654c6590f55"
integrity sha512-GK3g5RPZWTRSeLSpgP8Xhra+pnjBC56q9FZYe1d5RN3TJ35dbkGy3YqBSMbyCrlbi+CM9Z3Jk5yTL7RCsqboyQ==

lodash.template@^4.0.2:
version "4.5.0"
resolved "https://registry.yarnpkg.com/lodash.template/-/lodash.template-4.5.0.tgz#f976195cf3f347d0d5f52483569fe8031ccce8ab"
Expand Down

0 comments on commit d74e070

Please sign in to comment.