1var app = angular.module('MyApp', ['ngSanitize', 'ngCookies', 'pascalprecht.translate', 'slickCarousel', 'angular.filter']); 2 3app.controller('MyController', ['$scope', '$http', '$window', '$rootScope', '$translate', function ($scope, $http, $window) { 4 var apiUrl = document.querySelector('#ApiEndpoint').value; 5 $scope.prevEmployeeCategoryId = 0; 6 $scope.prevPostCategoryId = 0; 7 $scope.prevDocumentCategoryId = 0; 8 $scope.setValue = function (value) { 9 $scope['name' + value] = value; 10 } 11 $scope.changeLanguage = function (key) { 12 $rootScope.lang = key; 13 $translate.use(key); 14 }; 15 $scope.getPosts = function (Id, ParentId, AllowPaging, PageIndex, PageSize, CategoryId) { 16 console.log(CategoryId); 17 $scope['slickConfigLoaded_' + Id] = false; 18 if ($scope['posts_' + Id] !== undefined && $scope.prevPostCategoryId === CategoryId) { 19 PageIndex = $scope['posts_' + Id].length; 20 } 21 $http.get(apiUrl + "posttype?" + "ParentId=" + ParentId + '&AllowPaging=' + AllowPaging + '&PageIndex=' + PageIndex + '&PageSize=' + PageSize + '&CategoryId=' + CategoryId) 22 .then(function (response) { 23 if ($scope['posts_' + Id] !== undefined && $scope.prevPostCategoryId === CategoryId) { 24 angular.forEach(response.data, function (value, key) { 25 $scope['posts_' + Id].push(value); 26 }); 27 } 28 else { 29 $scope['posts_' + Id] = response.data; 30 $scope.prevPostCategoryId = CategoryId; 31 } 32 $scope['slickConfigLoaded_' + Id] = true; 33 }) 34 } 35 36 $scope.getEvents = function (Id, ParentId, AllowPaging, PageIndex, PageSize, NumberOfPostTypes) { 37 $http.get(apiUrl + "eventtype?" + "ParentId=" + ParentId + '&AllowPaging=' + AllowPaging + '&PageIndex=' + PageIndex + '&PageSize=' + PageSize + '&NumberOfPostTypes=' + NumberOfPostTypes) 38 .then(function (response) { 39 40 $scope['events_' + Id] = response.data; 41 }) 42 } 43 $scope.getGallery = function (ParentId, AllowPaging, PageIndex, PageSize, NumberOfPostTypes) { 44 var SecondTable = false; 45 if ($scope['gallery_' + ParentId] !== undefined) { 46 PageIndex = $scope['gallery_' + ParentId].length; 47 if ($scope['gallery_' + ParentId].filter(x => x.Name === null).length > 0) { 48 PageIndex = $scope['gallery_' + ParentId].filter(x => x.Name === null).length; 49 SecondTable = true; 50 } 51 } 52 $http.get(apiUrl + "MediaGallery?" + "ParentId=" + ParentId + '&AllowPaging=' + AllowPaging + '&PageIndex=' + PageIndex + '&PageSize=' + PageSize + '&SecondTable=' + SecondTable) 53 .then(function (response) { 54 console.log(response); 55 if ($scope['gallery_' + ParentId] !== undefined) { 56 angular.forEach(response.data, function (value, key) { 57 $scope['gallery_' + ParentId].push(value); 58 }); 59 } 60 else { 61 $scope['gallery_' + ParentId] = response.data; 62 } 63 $scope['slickConfigLoaded_' + ParentId] = true; 64 }) 65 } 66 $scope.getEventName = function (date) { 67 var monthNumber = date.split('-')[1]; 68 var monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Des']; 69 return monthNames[monthNumber - 1]; 70 } 71 72 $scope.getEmployees = function (Id, ParentId, AllowPaging, PageIndex, PageSize, CategoryId) { 73 74 if ($scope['employees_' + Id] !== undefined && $scope.prevEmployeeCategoryId === CategoryId) { 75 PageIndex = $scope['employees_' + Id].length; 76 } 77 $http.get(apiUrl + "employee?" + "ParentId=" + ParentId + '&AllowPaging=' + AllowPaging + '&PageIndex=' + PageIndex + '&PageSize=' + PageSize + '&CategoryId=' + CategoryId) 78 .then(function (response) { 79 console.log(response.data); 80 if ($scope['employees_' + Id] !== undefined && $scope.prevEmployeeCategoryId === CategoryId) { 81 angular.forEach(response.data, function (value, key) { 82 $scope['employees_' + Id].push(value); 83 }); 84 } 85 else { 86 $scope['employees_' + Id] = response.data; 87 $scope.prevEmployeeCategoryId = CategoryId; 88 } 89 }) 90 } 91 92 $scope.getCategories = function (ParentId) { 93 if ($scope['categories_' + ParentId] !== undefined) { 94 PageIndex = $scope['employees_' + Id].length; 95 } 96 $http.get(apiUrl + "Category?" + "ParentId=" + ParentId) 97 .then(function (response) { 98 if ($scope['categories_' + ParentId] !== undefined) { 99 angular.forEach(response.data, function (value, key) { 100 $scope['categories_' + ParentId].push(value); 101 }); 102 } 103 else { 104 $scope['categories_' + ParentId] = response.data; 105 } 106 }) 107 } 108 109 $scope.getImage = function (imagepath, width, height) {
110 return imagepath + "&width=" + width + "&height=" + height; 111 } 112 113 $scope.getClasses = function (ParentId) { 114 $http.get(apiUrl + 'DocumentType/GetClasses?ParentId=' + ParentId) 115 .then(function (response) { 116 console.log('API Response:', response.data); 117 $scope.classes = response.data; 118 }) 119 .catch(function (error) { 120 console.error('Error fetching classes:', error.status, error.data); 121 }); 122 }; 123 124 125 $scope.getDocuments = function (Id, ParentId, AllowPaging, PageIndex, PageSize, CategoryId) { 126 127 if ($scope['documents_' + Id] !== undefined && $scope.prevDocumentCategoryId === CategoryId) { 128 PageIndex = $scope['documents_' + Id].length; 129 } 130 131 $http.get(apiUrl + "documenttype?" + "ParentId=" + ParentId + '&AllowPaging=' + AllowPaging + '&PageIndex=' + PageIndex + '&PageSize=' + PageSize + '&CategoryId=' + CategoryId) 132 .then(function (response) { 133 console.log(response); 134 angular.forEach(response.data, function (value, key) { 135 if (value.CustomRedirect) { 136 if (value.InternalPageId > 0) { 137 value.PageUrl = value.InternalPageUrl; 138 } 139 else { 140 value.PageUrl = value.ExternalPage; 141 } 142 } 143 value.ContentLength = $scope.niceBytes(value.ContentLength); 144 }); 145 146 if ($scope['documents_' + Id] !== undefined && $scope.prevDocumentCategoryId === CategoryId) { 147 angular.forEach(response.data, function (value, key) { 148 $scope['documents_' + Id].push(value); 149 }); 150 } 151 else { 152 $scope['documents_' + Id] = response.data; 153 $scope.prevDocumentCategoryId = CategoryId; 154 } 155 }) 156 } 157 158 $scope.getWidgetText = function (Id) { 159 $http.get(apiUrl + "Widget?" + "Id=" + Id) 160 .then(function (response) { 161 $scope.widgetText = response.data.Text; 162 }) 163 } 164 165 const units = ['bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; 166 $scope.niceBytes = function (x) { 167 168 let l = 0, n = parseInt(x, 10) || 0; 169 170 while (n >= 1024 && ++l) { 171 n = n / 1024; 172 } 173 //include a decimal point and a tenths-place digit if presenting 174 //less than ten of KB or greater units 175 return (n.toFixed(n < 10 && l > 0 ? 1 : 0) + ' ' + units[l]); 176 } 177 178 $scope.slickConfig = { 179 enabled: true, 180 } 181 $scope.toggleSlick = function () { 182 $scope.slickConfig.enabled = !$scope.slickConfig.enabled; 183 } 184 185 $scope.slickConfig = { 186 method: {}, 187 dots: false, 188 infinite: false, 189 speed: 300, 190 autoplay: false, 191 responsive: [ 192 { 193 breakpoint: 600, 194 settings: { 195 slidesToShow: 1, 196 slidesToScroll: 1 197 } 198 }, 199 { 200 breakpoint: 480, 201 settings: { 202 slidesToShow: 1, 203 slidesToScroll: 1 204 } 205 } 206 ] 207 }; 208 209}]); 210 211app.directive('mySrc', ['$http', function ($http) { 212 return { 213 restrict: 'A', 214 scope: { 215 callback: '&' 216 }, 217 link: function (scope, elem, attrs) { 218 $http.get("/Website/ImageResizing?imageurl=" + scope.callback()) 219 .then(function (response) { 220 elem.attr('src', response.data.split(',')[1]); 221 elem.attr('data-src', response.data.split(',')[0]); 222 }); 223 224 } 225 }; 226}]); 227 228app.directive('onError', function () { 229 return { 230 restrict: 'A', 231 link: function (scope, element, attr) { 232 if (attr.ngSrc === "") { 233 element.attr('src', '/Apps/core/content/images/icon-no-image.svg'); 234 } 235 else { 236 element.on('error', function (result) { 237 element.attr('src', '/Apps/core/content/images/icon-no-image.svg'); 238 }); 239 } 240 } 241 } 242}); 243app.config(['$translateProvider', function ($translateProvider) { 244 $translateProvider 245 .useStaticFilesLoader({ 246 prefix: '/Areas/Admin/Content/Scripts/locales/bricknet.admin.local-', 247 suffix: '.json' 248 }) 249 .preferredLanguage('fo') 250 .useLocalStorage() 251 .useMissingTranslationHandlerLog()
252 .useSanitizeValueStrategy(null); 253}]); 254app.filter('groupBy', ['$parse', function ($parse) { 255 return function (list, group_by) { 256 257 var filtered = []; 258 var prev_item = null; 259 var group_changed = false; 260 // this is a new field which is added to each item where we append "_CHANGED" 261 // to indicate a field change in the list 262 //was var new_field = group_by + '_CHANGED'; - JB 12/17/2013 263 var new_field = 'group_by_CHANGED'; 264 265 // loop through each item in the list 266 angular.forEach(list, function (item) { 267 268 group_changed = false; 269 270 // if not the first item 271 if (prev_item !== null) { 272 273 // check if any of the group by field changed 274 275 //force group_by into Array 276 group_by = angular.isArray(group_by) ? group_by : [group_by]; 277 278 //check each group by parameter 279 for (var i = 0, len = group_by.length; i < len; i++) { 280 if ($parse(group_by[i])(prev_item) !== $parse(group_by[i])(item)) { 281 group_changed = true; 282 } 283 } 284 285 286 }// otherwise we have the first item in the list which is new 287 else { 288 group_changed = true; 289 } 290 291 // if the group changed, then add a new field to the item 292 // to indicate this 293 if (group_changed) { 294 item[new_field] = true; 295 } else { 296 item[new_field] = false; 297 } 298 299 filtered.push(item); 300 prev_item = item; 301 302 }); 303 304 return filtered; 305 }; 306}]); 307 308app.filter('chunk', function () { 309 function cacheIt(func) { 310 var cache = {}; 311 return function (arg, chunk_size) { 312 // if the function has been called with the argument 313 // short circuit and use cached value, otherwise call the 314 // cached function with the argument and save it to the cache as well then return 315 return cache[arg] ? cache[arg] : cache[arg] = func(arg, chunk_size); 316 }; 317 } 318 319 // unchanged from your example apart from we are no longer directly returning this â 320 function chunk(items, chunk_size) { 321 var chunks = []; 322 if (angular.isArray(items)) { 323 if (isNaN(chunk_size)) 324 chunk_size = 4; 325 for (var i = 0; i < items.length; i += chunk_size) { 326 chunks.push(items.slice(i, i + chunk_size)); 327 } 328 } else { 329 console.log("items is not an array: " + angular.toJson(items)); 330 } 331 return chunks; 332 } 333 // now we return the cached or memoized version of our chunk function 334 // if you want to use lodash this is really easy since there is already a chunk and memoize function all above code would be removed 335 // this return would simply be: return _.memoize(_.chunk); 336 337 return cacheIt(chunk); 338}); 339 340 341app.directive('lightgallery', function () { 342 return { 343 restrict: 'A', 344 link: function (scope, element, attrs) { 345 if (scope.$last) { 346 setTimeout(function () { 347 $(".fancybox-gallery").jqPhotoSwipe({ 348 galleryOpen: function (gallery) { 349 } 350 }); 351 }, 100); 352 } 353 } 354 }; 355});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.