Initial setup of mycontroller

This commit is contained in:
2019-11-28 09:16:11 -06:00
parent 62d71e30c1
commit 665eb783be
504 changed files with 212034 additions and 0 deletions

View File

@@ -0,0 +1,138 @@
/*
* Copyright 2015-2018 Jeeva Kandasamy (jkandasa@gmail.com)
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// don't forget to declare this service module as a dependency in your main app constructor!
//http://js2.coffee/#coffee2js
//https://coderwall.com/p/r_bvhg/angular-ui-bootstrap-alert-service-for-angular-js
myControllerModule.factory('alertService', function() {
var alertCfg = {};
alertCfg.displayTemplate = '<div class="col-xs-11 col-sm-3 toast-pf alert alert-{0} alert-dismissable">' +
'<button type="button" class="close" data-dismiss="alert" data-notify="dismiss" aria-hidden="true">' +
'<span class="pficon pficon-close"></span>' +
'</button>'+
'<span data-notify="icon"></span>' +
'<strong>{1}</strong> {2}' +
'<a href="{3}" target="{4}" data-notify="url"></a>'+
'</div>';
alertCfg.placement = "top";
alertCfg.delay = 1000;
alertCfg.timer = 1000;
return alertService = {
default: function(msg) {
$.notify({
icon: 'pficon pficon-info',
message: msg
},{
type: 'info',
delay: alertCfg.delay,
timer: alertCfg.timer,
placement: {
from: alertCfg.placement,
},
animate: {
enter: 'animated lightSpeedIn',
exit: 'animated lightSpeedOut'
},
template: alertCfg.displayTemplate,
});
},
success: function(msg){
$.notify({
icon: 'pficon pficon-ok',
message: msg
},{
type: 'success',
delay: alertCfg.delay,
timer: alertCfg.timer,
placement: {
from: alertCfg.placement,
},
animate: {
enter: 'animated lightSpeedIn',
exit: 'animated lightSpeedOut'
},
template: alertCfg.displayTemplate,
});
},
warning: function(msg){
$.notify({
icon: 'pficon pficon-warning-triangle-o',
message: msg
},{
type: 'warning',
delay: alertCfg.delay,
timer: alertCfg.timer,
placement: {
from: alertCfg.placement,
},
animate: {
enter: 'animated lightSpeedIn',
exit: 'animated lightSpeedOut'
},
template: alertCfg.displayTemplate,
});
},
danger: function(msg){
$.notify({
icon: 'pficon pficon-error-circle-o',
message: msg
},{
type: 'danger',
delay: alertCfg.delay,
timer: alertCfg.timer,
placement: {
from: alertCfg.placement,
},
animate: {
enter: 'animated lightSpeedIn',
exit: 'animated lightSpeedOut'
},
template: alertCfg.displayTemplate,
});
}
};
}
);
myControllerModule.factory('displayRestError', function(alertService){
return displayRestError = {
display: function(error){
//alertService.danger(angular.toJson(error));
var displayMessage = '';
if(error.status === 0){
displayMessage = 'NO RESPONSE, Check your network connection [or] Server status!';
}else if(error.data != null){
if(error.data.errorMessage != null){
displayMessage = error.status +': '+ error.statusText+'<br>'+error.data.errorMessage;
} else if(error.data.message != null) {
displayMessage = error.status +': '+ error.statusText+'<br>'+error.data.message;
} else {
displayMessage = error.status +': '+ error.statusText;
}
}else if(data != null){
displayMessage = error.status +': '+ error.statusText;
}
alertService.danger(displayMessage);
},
displayMsg: function(response, expectedCode, successDisplay){
alertService.success(angular.toJson(response));
}
};
});

View File

@@ -0,0 +1,538 @@
/*
* Copyright 2015-2018 Jeeva Kandasamy (jkandasa@gmail.com)
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// don't forget to declare this service module as a dependency in your main app constructor!
//http://js2.coffee/#coffee2js
//https://coderwall.com/p/r_bvhg/angular-ui-bootstrap-alert-service-for-angular-js
myControllerModule.factory('CommonServices', function(TypesFactory, $filter, $cookies, mchelper) {
var commonService = {};
//get mchelper configurations
commonService.loadMchelper = function(){
var mchelperLocal = $cookies.getObject('mchelper');
if(mchelperLocal){
mchelper.cfg = mchelperLocal.cfg || {};
mchelper.user = mchelperLocal.user || {};
mchelper.languages = mchelperLocal.languages || {};
mchelper.userSettings = mchelperLocal.userSettings || {};
mchelper.internal = mchelperLocal.internal || {};
}
return mchelper;
};
//restore store all the configurations locally
commonService.saveMchelper = function(mchelperRemote){
mchelper.cfg = mchelperRemote.cfg;
mchelper.user = mchelperRemote.user;
mchelper.languages = mchelperRemote.languages;
mchelper.userSettings = mchelperRemote.userSettings;
mchelper.internal = mchelperRemote.internal;
$cookies.putObject('mchelper', mchelper);
};
//clear local mchelper
commonService.clearMchelper = function(){
mchelper.selectedDashboard = undefined;
mchelper.cfg = {};
mchelper.user = {};
mchelper.languages = {};
mchelper.userSettings = {};
mchelper.internal = {};
};
//remove cookies
commonService.clearCookies = function(){
var cookies = $cookies.getAll();
angular.forEach(cookies, function (v, k) {
$cookies.remove(k);
});
};
//Get value nested supported
commonService.getValue = function(item, key){
var keys = key.split('.');
for (var i = 0, n = keys.length; i < n; ++i) {
var k = keys[i];
if (k in item) {
item = item[k];
} else {
return;
}
}
return item;
};
//Match value
var matchesFilter = function (item, filter) {
var match = true;
var value = commonService.getValue(item, filter.id);
//TODO: there is an issue with sensors action page. filter is not passing the type.
//workaround, if undefined, set as type 'text'
if(filter.type === undefined){
if(angular.isNumber(value)){
filter.value = parseInt(filter.value);
filter.type = 'object';
}else{
filter.type = 'text';
}
}
if(filter.type === 'text' || filter.type === 'select'){
if(value){
match = value.toUpperCase().match(filter.value.toUpperCase()) !== null;
}else{
match = false;
}
}else if(filter.type === 'array'){
return value.indexOf(filter.value) > -1;
}else{
match = angular.equals(value, filter.value);
}
return match;
};
//Match values with for loop
var matchesFilters = function (item, filters) {
var matches = true;
filters.forEach(function(filter) {
if (!matchesFilter(item, filter)) {
matches = false;
return false;
}
});
return matches;
};
//Apply filter
var applyFilters = function (filters, configMap) {
configMap.filteredList = [];
if (filters && filters.length > 0) {
configMap.orgList.forEach(function (item) {
if (matchesFilters(item, filters)) {
configMap.filteredList.push(item);
}
});
} else {
configMap.filteredList = configMap.orgList;
}
configMap.filterConfig.resultsCount = configMap.filteredList.length;
};
// Common filter
commonService.filterChangeLocal = function (filters, configMap) {
configMap.filtersText = "";
filters.forEach(function (filter) {
configMap.filtersText += filter.title + " : " + filter.value + "\n";
});
applyFilters(filters, configMap);
};
//Select/unselect single row of table
commonService.selectItem = function (baseScope, item, key){
if(!key){
key='id';
}
if(baseScope.itemIds.indexOf(item[key]) == -1){
baseScope.itemIds.push(item[key]);
}else{
baseScope.itemIds.splice(baseScope.itemIds.indexOf(item[key]), 1);
}
};
// select ALL/NONE of table row function
commonService.selectAllItems = function (baseScope, key) {
if(!key){
key='id';
}
if(baseScope.filteredList.length > 0){
if(baseScope.filteredList.length == baseScope.itemIds.length){
baseScope.itemIds = [];
}else{
baseScope.itemIds = [];
angular.forEach(baseScope.filteredList, function(value, keyT) {
baseScope.itemIds.push(value[key]);
});
}
}
};
// Update row selection of table function
commonService.updateSelection = function (baseScope) {
if(baseScope.itemIds.length > 0){
tmpItemIds = baseScope.itemIds;
baseScope.itemIds = [];
angular.forEach(baseScope.filteredList, function(value, key) {
if(tmpItemIds.indexOf(value.id) != -1){
baseScope.itemIds.push(value.id);
}
});
}
};
// get Table configuration
commonService.getTableConfig = function(){
return config = {
itemsPerPage: 15,
maxPages:10,
fillLastPage: false
};
};
// get resources
commonService.getResources= function(resourceType, resourceId){
if(resourceType === 'Sensor variable'){
return TypesFactory.getSensorVariables();
}else if(resourceType === 'Gateway' || resourceType === 'Gateway state'){
return TypesFactory.getGateways();
}else if(resourceType === 'Node' || resourceType === 'Node state'){
return TypesFactory.getNodes({"gatewayId":resourceId});
}else if(resourceType === 'Sensors'){
return TypesFactory.getSensors({"nodeId":resourceId});
}else if(resourceType === 'Resources group'){
return TypesFactory.getResourcesGroups();
}else if(resourceType === 'Alarm definition'){
return TypesFactory.getAlarmDefinitions();
}else if(resourceType === 'Timer'){
return TypesFactory.getTimers();
}else{
return null;
}
}
// get Table configuration
commonService.getQuery = function(){
return query = {
pageLimit: mchelper.cfg.tableRowsLimit,
page: 1,
orderBy: "id",
order: "asc"
};
};
//Apply filters
commonService.updateFiltersChange = function (remoteScope, filters) {
//Clears filter
remoteScope.filterConfig.fields.forEach(function (filter) {
if(filter.filterType === 'text'){
remoteScope.query[filter.id]=[];
}else if(filter.filterType === 'select'){
remoteScope.query[filter.id] = null;
}
});
//Update filters
filters.forEach(function (filter) {
//This is to fix sensors action page
//console.log(''+angular.toJson(filter));
if(filter.type === undefined){
remoteScope.filterConfig.fields.forEach(function (orgFilter) {
if(filter.id === orgFilter.id){
filter.type = orgFilter.filterType;
}
});
}
if(filter.type === 'text'){
remoteScope.query[filter.id].push(filter.value);
}else if(filter.type === 'select'){
remoteScope.query[filter.id] = filter.value;
}
});
//move to page number 1 on filter change
remoteScope.currentPage = 1;
remoteScope.query.page=1;
remoteScope.getAllItems();
};
//Update sort columns(orderBy)
commonService.updateSortChange = function (remoteScope, sortId, isAscending) {
if(isAscending){
remoteScope.query.order = "asc";
}else{
remoteScope.query.order = "dsec";
}
remoteScope.query.orderBy = sortId.id;
remoteScope.getAllItems();
};
//Update page change
commonService.updatePageChange = function (remoteScope, newPage) {
remoteScope.query.page = newPage;
remoteScope.getAllItems();
};
//Get min number
commonService.getMin = function(item1, item2){
return Math.min(item1, item2);
};
//item for sensor actions
//--------------------------------------------------
//Defined variable types list
commonService.getSensorVariablesKnownList = function(){
var definedVariableTypes = ["Status","Watt","Temperature","Humidity","Pressure","Forecast","Armed","Tripped","Lock status","Percentage","Weight","Stop","Up","Down","Rain","Rain rate",
"HVAC flow state","HVAC flow mode","HVAC speed","HVAC setpoint cool","HVAC setpoint heat","Variable 1","Variable 2","Variable 3","Variable 4","Variable 5","RGB","RGBW","Distance",
"Current","Voltage","Impedance", "Volume"];
return definedVariableTypes;
};
//Forecast mapper
var forecastMapper = [
{
id:"sunny",
value:"day-sunny",
},{
id:"cloudy",
value:"day-cloudy",
},{
id:"thunderstorm",
value:"day-thunderstorm",
},{
id:"stable",
value:"day-sunny",
},{
id:"unstable",
value:"sprinkle",
},{
id:"na",
value:"na",
},
];
commonService.getForecastValue = function(key){
if(key === undefined){
key = 'na';
}
var result = $filter('filter')(forecastMapper, {id: key}, true)[0];
if(!result){
return "na";
}else{
return result.value
}
//return $filter('filter')($scope.forecastMapper, {id: key}, true)[0].value;
};
//Sensor icons
var sensorIcons = [
{id:"default", value:"fa fa-eye", ucode:"\uf06e", fname:"FontAwesome"},
{id:"Door", value:"fa fa-building-o", ucode:"\uf0f7", fname:"FontAwesome"},
{id:"Motion", value:"fa fa-paw", ucode:"\uf1b0", fname:"FontAwesome"},
{id:"Smoke", value:"wi wi-smoke", ucode:"\uf062", fname:"weathericons"},
{id:"Binary", value:"fa fa-power-off", ucode:"\uf011", fname:"FontAwesome"},
{id:"Dimmer", value:"fa fa-lightbulb-o", ucode:"\uf0eb", fname:"FontAwesome"},
{id:"Cover", value:"fa fa-archive", ucode:"\uf187", fname:"FontAwesome"},
{id:"Temperature", value:"wi wi-thermometer", ucode:"\uf055", fname:"weathericons"},
{id:"Humidity", value:"wi wi-humidity", ucode:"\uf07a", fname:"weathericons"},
{id:"Barometer", value:"wi wi-barometer", ucode:"\uf079", fname:"weathericons"},
{id:"Wind", value:"wi wi-windy", ucode:"\uf079", fname:"weathericons"},
{id:"Rain", value:"wi wi-raindrops", ucode:"\uf04e", fname:"weathericons"},
{id:"UV", value:"fa fa-eye", ucode:"\uf06e", fname:"FontAwesome"},
{id:"Weight", value:"fa fa-balance-scale", ucode:"\uf24e", fname:"FontAwesome"},
{id:"Power", value:"fa fa-bolt", ucode:"\uf0e7", fname:"FontAwesome"},
{id:"Heater", value:"fa fa-eye", ucode:"\uf06e", fname:"FontAwesome"},
{id:"Distance", value:"fa fa-binoculars", ucode:"\uf1e5", fname:"FontAwesome"},
{id:"Light level", value:"wi wi-moon-alt-waxing-crescent-5", ucode:"\uf0d4", fname:"weathericons"},
{id:"Node", value:"fa fa-sitemap", ucode:"\uf0e8", fname:"FontAwesome"},
{id:"Repeater node", value:"fa fa-sitemap", ucode:"\uf0e8", fname:"FontAwesome"},
{id:"Lock", value:"fa fa-lock", ucode:"\uf023", fname:"FontAwesome"},
{id:"IR", value:"fa fa-eye", ucode:"\uf06e", fname:"FontAwesome"},
{id:"Water", value:"fa fa-eye", ucode:"\uf06e", fname:"FontAwesome"},
{id:"Air quality", value:"fa fa-eye", ucode:"\uf06e", fname:"FontAwesome"},
{id:"Custom", value:"fa fa-eye", ucode:"\uf06e", fname:"FontAwesome"},
{id:"Dust", value:"wi wi-dust", ucode:"\uf063", fname:"weathericons"},
{id:"Scene controller", value:"fa fa-picture-o", ucode:"\uf03e", fname:"FontAwesome"},
{id:"RGB light", value:"fa fa-eye", ucode:"\uf06e", fname:"FontAwesome"},
{id:"RGBW light", value:"fa fa-eye", ucode:"\uf06e", fname:"FontAwesome"},
{id:"Color sensor", value:"fa fa-eye", ucode:"\uf06e", fname:"FontAwesome"},
{id:"HVAC", value:"fa fa-eye", ucode:"\uf06e", fname:"FontAwesome"},
{id:"Multimeter", value:"fa fa-calculator", ucode:"\uf1ec", fname:"FontAwesome"},
{id:"Sprinkler", value:"fa fa-eye", ucode:"\uf06e", fname:"FontAwesome"},
{id:"Water leak", value:"fa fa-tint", ucode:"\uf043", fname:"FontAwesome"},
{id:"Sound", value:"fa fa-volume-up", ucode:"\uf028", fname:"FontAwesome"},
{id:"Vibration", value:"fa fa-eye", ucode:"\uf06e", fname:"FontAwesome"},
{id:"Moisture", value:"fa fa-eye", ucode:"\uf06e", fname:"FontAwesome"},
{id:"Information", value:"fa fa-info", ucode:"\uf129", fname:"FontAwesome"},
{id:"Gas", value:"fa fa-eye", ucode:"\uf06e", fname:"FontAwesome"},
{id:"GPS", value:"fa fa-eye", ucode:"\uf06e", fname:"FontAwesome"},
{id:"Water quality", value:"fa fa-eye", ucode:"\uf06e", fname:"FontAwesome"},
{id:"CPU", value:"fa fa-eye", ucode:"\uf06e", fname:"FontAwesome"},
{id:"Memory", value:"fa fa-eye", ucode:"\uf06e", fname:"FontAwesome"},
{id:"Disk", value:"fa fa-eye", ucode:"\uf06e", fname:"FontAwesome"},
{id:"PWM", value:"fa fa-eye", ucode:"\uf06e", fname:"FontAwesome"},
];
commonService.getSensorIcon = function(key){
return commonService.getSensorIconData(key).value;
};
commonService.getSensorIconData = function(key){
if(key === undefined || key == 'Undefined'){
key = 'default';
}
return $filter('filter')(sensorIcons, {id: key}, true)[0];
};
//RGBA functions
//Function to convert rgba format to hex color
commonService.rgba2hex = function rgb2hex(rgb){
rgb = rgb.replace("rgba","").replace("(","").replace(")","").split(",");
return "#"
+ ("0" + parseInt(rgb[0],10).toString(16)).slice(-2)
+ ("0" + parseInt(rgb[1],10).toString(16)).slice(-2)
+ ("0" + parseInt(rgb[2],10).toString(16)).slice(-2)
+ ("0" + parseInt((parseFloat(rgb[3],10)*255)).toString(16)).slice(-2);
};
//Function to convert hex format to RGBA color
commonService.hex2rgba = function(hex){
if(hex){
hex = hex.replace('#','');
r = parseInt(hex.substring(0,2), 16);
g = parseInt(hex.substring(2,4), 16);
b = parseInt(hex.substring(4,6), 16);
opacity = parseInt(hex.substring(6,8), 16);
result = 'rgba('+r+','+g+','+b+','+(opacity/255).toFixed(2)+')';
return result;
}
return undefined;
};
//Get integer value for switch
commonService.getInteger = function(value){
if(!value){
return undefined;
}else{
return parseInt(value);
}
};
//Switch settings
commonService.mcbStyle = {
handleWidth: "60px",
stateHandleWidth: "35px",
labelWidth: "3px",
animate:true,
size:"small",
};
//validation methods
//-----------------------
//Number validation
commonService.isNumber = function (value) {
if (isNaN(value)) {
return false;
}
return true;
};
//is contains space validation
commonService.isContainsSpace = function (value) {
if(value !== undefined){
return !value.match(/\s/g);
}
return true;
};
//is valid JSON
commonService.isJsonString = function (value) {
try {
JSON.stringify(eval('('+value+')'));
return true;
} catch(err) {
return false;
}
};
//guid helper
var s4 = function() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
}
//get guid
commonService.guid = function() {
return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();
};
//get friendly time
commonService.getTimestampJson = function(timestamp){
var timestampJson = {};
if(timestamp % 31536000000 == 0){
timestampJson.timestamp = timestamp / 31536000000;
timestampJson.timeConstant = "31536000000";
timestampJson.timeConstantString = $filter('translate')('YEARS');
}else if(timestamp % 86400000 == 0){
timestampJson.timestamp = timestamp / 86400000;
timestampJson.timeConstant = "86400000";
timestampJson.timeConstantString = $filter('translate')('DAYS');
}else if(timestamp % 3600000 == 0){
timestampJson.timestamp = timestamp / 3600000;
timestampJson.timeConstant = "3600000";
timestampJson.timeConstantString = $filter('translate')('Hours');
}else if(timestamp % 60000 == 0){
timestampJson.timestamp = timestamp / 60000;
timestampJson.timeConstant = "60000";
timestampJson.timeConstantString = $filter('translate')('Minutes');
}
return timestampJson;
};
//get timestamp
commonService.getTimestamp = function(timestampJson){
return timestampJson.timeConstant * timestampJson.timestamp;
};
//Update mill seconds to readable value
commonService.updateReadable = function(milliSeconds, item){
if(milliSeconds % 86400000 == 0){
item.readableValue = milliSeconds / 86400000;
item.timeConstant = "86400000";
}else if(milliSeconds % 3600000 == 0){
item.readableValue = milliSeconds / 3600000;
item.timeConstant = "3600000";
}else if(milliSeconds % 60000 == 0){
item.readableValue = milliSeconds / 60000;
item.timeConstant = "60000";
}else{
item.readableValue = milliSeconds / 1000;
item.timeConstant = "1000";
}
};
//Get readable value to milliseconds
commonService.getMilliseconds = function(readableValue, timeConstant){
return readableValue * timeConstant;
};
//Update default graph margin settings
commonService.updateGraphMarginDefault = function(item){
if(item.marginTop === undefined){
item.marginTop = 5;
item.marginRight = 20;
item.marginBottom = 60;
item.marginLeft = 65;
}
}
return commonService;
});

View File

@@ -0,0 +1,43 @@
/*
* Copyright 2015-2018 Jeeva Kandasamy (jkandasa@gmail.com)
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
myControllerModule.directive('mcDynamic', function ($compile) {
return {
restrict: 'E',
replace: true,
link: function (scope, ele, attrs) {
scope.$watch(attrs.ngBindHtml, function() {
ele.html(scope.ngBindHtml);
$compile(ele.contents())(scope);
});
}
};
});
myControllerModule.directive('convertToNumber', function() {
return {
require: 'ngModel',
link: function(scope, element, attrs, ngModel) {
ngModel.$parsers.push(function(val) {
return val != null ? parseInt(val, 10) : null;
});
ngModel.$formatters.push(function(val) {
return val != null ? '' + val : null;
});
}
};
});

View File

@@ -0,0 +1,516 @@
/*
* Copyright 2015-2018 Jeeva Kandasamy (jkandasa@gmail.com)
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict';
//Sensors Services
myControllerModule.factory('SensorsFactory', function ($resource, $http, $base64) {
return $resource('/mc/rest/sensors/:sensorId/:id', {sensorId: '@sensorId'}, {
getAll: { method: 'GET', isArray: false},
get: { method: 'GET', isArray: false, params: {sensorId: '@sensorId', id:null}},
create: { method: 'POST', params: {sensorId: null}},
update: { method: 'PUT', params: {sensorId: null}},
delete: { method: 'DELETE', params: {sensorId: '@sensorId'} },
deleteIds: { method: 'POST', params: {sensorId: 'deleteIds'} },
updateVariable: { method: 'PUT', params: {sensorId: 'updateVariable', id:null}},
updateVariableConfig: { method: 'PUT', params: {sensorId: 'updateVariableConfig', id:null}},
purgeVariable: { method: 'PUT', params: {sensorId: 'purgeVariable', id:null}},
getVariables: { method: 'GET', isArray: true, params: {sensorId: 'getVariables', id:null}},
getVariable: { method: 'GET', isArray: false, params: {sensorId: 'getVariable'}},
sendRawMessage: { method: 'POST', params: {sensorId:'sendRawMessage'} },
})
});
//Node Services
myControllerModule.factory('NodesFactory', function ($resource) {
return $resource('/mc/rest/nodes/:nodeId', {nodeId: '@nodeId'}, {
getAll: { method: 'GET', isArray: false },
get: { method: 'GET' },
create: { method: 'POST'},
update: { method: 'PUT' },
delete: { method: 'DELETE'},
deleteIds: { method: 'POST', params: {nodeId: 'deleteIds'}},
reboot: { method: 'POST', params: {nodeId: 'reboot'}},
eraseConfiguration: { method: 'POST', params: {nodeId: 'eraseConfiguration'}},
executeNodeInfoUpdate: { method: 'POST', params: {nodeId: 'executeNodeInfoUpdate'}},
uploadFirmware: { method: 'POST', params: {nodeId: 'uploadFirmware'}},
})
});
//Firmware Services
myControllerModule.factory('FirmwaresFactory', function ($resource) {
return $resource('/mc/rest/firmwares/:type/:refId', {}, {
getAllFirmwareTypes: { method: 'GET', isArray: false, params: {type: 'types'}},
getAllFirmwareVersions: { method: 'GET', isArray: false, params: {type: 'versions'}},
getAllFirmwares: { method: 'GET', isArray: false, params: {type: 'firmwares'}},
getFirmwareType: { method: 'GET', isArray: false, params: {type: 'types', id: '@refId'}},
getFirmwareVersion: { method: 'GET', isArray: false, params: {type: 'versions', id: '@refId'}},
getFirmware: { method: 'GET', isArray: false, params: {type: 'firmwares', id: '@refId'}},
deleteFirmwareTypes: { method: 'POST', params: {type: 'types', refId: 'delete'}},
deleteFirmwareVersions: { method: 'POST', params: {type: 'versions', refId: 'delete'}},
deleteFirmwares: { method: 'POST', params: {type: 'firmwares', refId: 'delete'}},
updateFirmwareType: { method: 'PUT', params: {type: 'types'}},
updateFirmwareVersion: { method: 'PUT', params: {type: 'versions'}},
updateFirmware: { method: 'PUT', params: {type: 'firmwares'}},
createFirmwareType: { method: 'POST', params: {type: 'types'}},
createFirmwareVersion: { method: 'POST', params: {type: 'versions'}},
createFirmware: { method: 'POST', params: {type: 'firmwares'}}
})
});
//Types Services
myControllerModule.factory('TypesFactory', function ($resource) {
return $resource('/mc/rest/types/:type/:id', {id: '@id'}, {
getNodeTypes: { method: 'GET', isArray: true, params: {type: 'nodeTypes'} },
getExternalServerTypes: { method: 'GET', isArray: true, params: {type: 'externalServerTypes'} },
getMetricEngineTypes: { method: 'GET', isArray: true, params: {type: 'metricEngineTypes'} },
getTrustHostTypes: { method: 'GET', isArray: true, params: {type: 'trustHostTypes'} },
getNodeRegistrationStatuses: { method: 'GET', isArray: true, params: {type: 'nodeRegistrationStatuses'} },
getSensorTypes: { method: 'GET', isArray: true, params: {type: 'sensorTypes'}},
getMetricTypes: { method: 'GET', isArray: true, params: {type: 'metricTypes'}},
getUnitTypes: { method: 'GET', isArray: true, params: {type: 'unitTypes'}},
getSensorVariableTypes: { method: 'GET', isArray: true, params: {type: 'sensorVariableTypes', id : null} },
getGatewayTypes: { method: 'GET', isArray: true, params: {type: 'gatewayTypes'} },
getGatewayNetworkTypes: { method: 'GET', isArray: true, params: {type: 'gatewayNetworkTypes'} },
getGatewaySerialDrivers: { method: 'GET', isArray: true, params: {type: 'gatewaySerialDrivers'} },
getResourceTypes: { method: 'GET', isArray: true, params: {type: 'resourceTypes'} },
getGateways: { method: 'GET', isArray: true, params: {type: 'gateways'} },
getNodes: { method: 'GET', isArray: true, params: {type: 'nodes'} },
getExternalServers: { method: 'GET', isArray: true, params: {type: 'externalServers'} },
getSensors: { method: 'GET', isArray: true, params: {type: 'sensors'} },
getSensorVariables: { method: 'GET', isArray: true, params: {type: 'sensorVariables'} },
getRuleDefinitions: { method: 'GET', isArray: true, params: {type: 'ruleDefinitions'} },
getTimers: { method: 'GET', isArray: true, params: {type: 'timers'} },
getForwardPayloads: { method: 'GET', isArray: true, params: {type: 'forwardPayloads'} },
getSensorValueTypes: { method: 'GET', isArray: true, params: {type: 'sensorValueTypes'} },
getResourcesGroups: { method: 'GET', isArray: true, params: {type: 'resourcesGroups'} },
getOperationTypes: { method: 'GET', isArray: true, params: {type: 'operationTypes'} },
getRuleOperatorTypes: { method: 'GET', isArray: true, params: {type: 'ruleOperatorTypes'} },
getRuleThresholdDataTypes: { method: 'GET', isArray: true, params: {type: 'ruleThresholdDataTypes'} },
getRuleDampeningTypes: { method: 'GET', isArray: true, params: {type: 'ruleDampeningTypes'} },
getStateTypes: { method: 'GET', isArray: true, params: {type: 'stateTypes'} },
getPayloadOperations: { method: 'GET', isArray: true, params: {type: 'payloadOperations'} },
getRuleConditionTypes: { method: 'GET', isArray: true, params: {type: 'ruleConditionTypes'} },
//Timers
getTimerTypes: { method: 'GET', isArray: true, params: {type: 'timerTypes'} },
getTimerFrequencies: { method: 'GET', isArray: true, params: {type: 'timerFrequencyTypes'} },
getTimerWeekDays: { method: 'GET', isArray: true, params: {type: 'timerWeekDays', id:null} },
//Firmwares
getFirmwares: { method: 'GET', isArray: true, params: {type: 'firmwares'}},
getFirmwareTypes: { method: 'GET', isArray: true, params: {type: 'firmwareTypes'}},
getFirmwareVersions: { method: 'GET', isArray: true, params: {type: 'firmwareVersions'}},
getSensorVariableMapper: { method: 'GET', isArray: true, params: {type: 'sensorVariableMapper'} },
getSensorVariableMapperByType: { method: 'GET', isArray: true, params: {type: 'sensorVariableMapperByType', id:null} },
updateSensorVariableMapper: { method: 'PUT', params: {type: 'sensorVariableMapper', id : null} },
getLanguages: { method: 'GET', isArray: true, params: {type: 'languages', id : null}},
getHvacOptionsFlowState: { method: 'GET', isArray: true, params: {type: 'hvacOptionsFlowState', id : null}},
getHvacOptionsFlowMode: { method: 'GET', isArray: true, params: {type: 'hvacOptionsFlowMode', id : null}},
getHvacOptionsFanSpeed: { method: 'GET', isArray: true, params: {type: 'hvacOptionsFanSpeed', id : null}},
getRolePermissions: { method: 'GET', isArray: true, params: {type: 'rolePermissions', id : null}},
//Operations
getOperations: { method: 'GET', isArray: true, params: {type: 'operations'} },
//Rooms
getRooms: { method: 'GET', isArray: true, params: {type: 'rooms'} },
getResources: { method: 'GET', isArray: true, params: {type: 'resources'} },
getUserRoles: { method: 'GET', isArray: true, params: {type: 'roles'} },
getGraphInterpolateTypes: { method: 'GET', isArray: true, params: {type: 'graphInterpolate'} },
getMysConfigTypes: { method: 'GET', isArray: true, params: {type: 'mysConfigTypes'} },
getSensorVariableTypesBySensorRefId: { method: 'GET', isArray: true, params: {type: 'sensorVariableTypesBySenRef'} },
getMessageTypes: { method: 'GET', isArray: true, params: {type: 'messageTypes'} },
getMessageSubTypes: { method: 'GET', isArray: true, params: {type: 'messageSubTypes'} },
getGraphSensorVariableTypes: { method: 'GET', isArray: true, params: {type: 'graphSensorVariableTypes'} },
getTime12h24hformats: { method: 'GET', isArray: true, params: {type: 'time12h24hformats'} },
//ResourcesLogs
getResourceLogsMessageTypes: { method: 'GET', isArray: true, params: {type: 'resourceLogsMessageTypes'} },
getResourceLogsLogDirections: { method: 'GET', isArray: true, params: {type: 'resourceLogsLogDirections'} },
getResourceLogsLogLevels: { method: 'GET', isArray: true, params: {type: 'resourceLogsLogLevels'} },
//Metrics
getMetricsSettings: { method: 'GET', isArray: false, params: {type: 'metricsSettings', id:null} },
})
});
//Metrics Services
myControllerModule.factory('MetricsFactory', function ($resource) {
return $resource('/mc/rest/metrics/:type', {}, {
getResourceCount: { method: 'GET', isArray: false, params: {type: 'resourceCount'}},
getMetricsData: { method: 'GET', isArray: true, params: {type: 'nvd3data'}},
getBatteryMetrics: { method: 'GET', isArray: false, params: {type: 'statsBattery'}},
getBulletChart: { method: 'GET', isArray: true, params: {type: 'bulletChart'}},
getTopologyData: { method: 'GET', isArray: false, params: {type: 'topology'}},
getHeatMapBatteryLevel: { method: 'GET', isArray: true, params: {type: 'heatMapBatteryLevel'}},
getHeatMapHeatMapNodeStatus: { method: 'GET', isArray: true, params: {type: 'heatMapNodeStatus'}},
getHeatMapHeatMapSensorVariable: { method: 'GET', isArray: true, params: {type: 'heatMapSensorVariable'}},
getHeatMapHeatMapScript: { method: 'GET', isArray: true, params: {type: 'heatMapScript'}},
getCsvFile: { method: 'GET', isArray: false, params: {type: 'csvFile'}},
})
});
//Authentication Services
myControllerModule.factory('AuthenticationFactory', function ($resource) {
return $resource('/mc/rest/authentication/login', {}, {
login: { method: 'POST'}
})
});
myControllerModule.factory('AuthenticationService',
function (AuthenticationFactory,$base64, $http, CommonServices, mchelper) {
var service = {};
service.Login = function (username, password, callback) {
$http.defaults.headers.common['Authorization'] = 'Basic ' + $base64.encode(username + ':' + password);
/* Use this for real authentication
----------------------------------------------*/
$http.post('/mc/rest/authentication/login', { username: username, password: password })
.success(function (response) {
callback(response);
}).error(function(response) {
callback(response);
});
};
service.SetCredentials = function (username, password) {
var authdata = $base64.encode(username + ':' + password);
mchelper.internal = {
currentUser: {
username: username,
authdata: authdata
}
};
$http.defaults.headers.common['Authorization'] = 'Basic ' + authdata; // jshint ignore:line
//Save in cookies
CommonServices.saveMchelper(mchelper);
};
service.ClearCredentials = function () {
$http.defaults.headers.common.Authorization = 'Basic ';
//clear mchelper auth record
CommonServices.clearMchelper();
CommonServices.clearCookies();
};
return service;
});
//Security Services
myControllerModule.factory('SecurityFactory', function ($resource) {
return $resource('/mc/rest/security/:type/:id', {}, {
getAllRoles: { method: 'GET', isArray: false, params: {type: 'roles', id:null, 'onlyRolename':null}},
getAllRolesSimple: { method: 'GET', isArray: true, params: {type: 'roles', id:null, 'onlyRolename':true}},
getRole: { method: 'GET', isArray: false, params: {type: 'roles', id:'@id'}},
createRole: { method: 'POST', isArray: false, params: {type: 'roles', id:null}},
updateRole: { method: 'PUT', isArray: false, params: {type: 'roles', id:null}},
deleteRoleIds: { method: 'POST', isArray: false, params: {type: 'roles', id:'delete'}},
getAllUsers: { method: 'GET', isArray: false, params: {type: 'users', id:null, 'onlyUsername':null}},
getAllUsersSimple: { method: 'GET', isArray: true, params: {type: 'users', id:null, 'onlyUsername':true}},
getUser: { method: 'GET', isArray: false, params: {type: 'users', id:'@id'}},
createUser: { method: 'POST', isArray: false, params: {type: 'users', id:null}},
updateUser: { method: 'PUT', isArray: false, params: {type: 'users', id:null}},
deleteUserIds: { method: 'POST', isArray: false, params: {type: 'users', id:'delete'}},
enableUserIds: { method: 'POST', isArray: false, params: {type: 'users', id:'enable'}},
disableUserIds: { method: 'POST', isArray: false, params: {type: 'users', id:'disable'}},
getProfile: { method: 'GET', isArray: false, params: {type: 'profile', id:null}},
updateProfile: { method: 'PUT', isArray: false, params: {type: 'profile', id:null}},
})
});
//Alarm Services
myControllerModule.factory('RulesFactory', function ($resource) {
return $resource('/mc/rest/rules/:id', {id: '@id'}, {
getAll: { method: 'GET', isArray: false, params: {id: null} },
get: { method: 'GET' },
create: { method: 'POST', params: {id: null}},
update: { method: 'PUT', params: {id: null}},
deleteIds: { method: 'POST', params: {id: 'delete'}},
enableIds: { method: 'POST', params: {id: 'enable'}},
disableIds: { method: 'POST', params: {id: 'disable'}},
})
});
//Operations Services
myControllerModule.factory('OperationsFactory', function ($resource) {
return $resource('/mc/rest/operations/:id', {id: '@id'}, {
getAll: { method: 'GET', isArray: false, params: {id: null} },
get: { method: 'GET' },
create: { method: 'POST', params: {id: null}},
update: { method: 'PUT', params: {id: null}},
deleteIds: { method: 'POST', params: {id: 'delete'}},
enableIds: { method: 'POST', params: {id: 'enable'}},
disableIds: { method: 'POST', params: {id: 'disable'}},
})
});
//Timer Services
myControllerModule.factory('TimersFactory', function ($resource) {
return $resource('/mc/rest/timers/:id', {id: '@id'}, {
getAll: { method: 'GET', isArray: false, params: {id: null} },
get: { method: 'GET' },
create: { method: 'POST', params: {id: null}},
update: { method: 'PUT', params: {id: null} },
deleteIds: { method: 'POST', params: {id: 'delete'} },
disableIds: { method: 'POST', params: {id: 'disable'} },
enableIds: { method: 'POST', params: {id: 'enable'} },
})
});
//ForwardPayload Services
myControllerModule.factory('ForwardPayloadFactory', function ($resource) {
return $resource('/mc/rest/forwardpayload/:id', {id: '@id'}, {
getAll: { method: 'GET', isArray: false, params: {id: null}},
create: { method: 'POST', params: {id: null}},
deleteIds: { method: 'POST', params: {id: 'delete'}},
enableIds: { method: 'POST', params: {id: 'enable'}},
disableIds: { method: 'POST', params: {id: 'disable'}},
get: { method: 'GET'},
update: { method: 'PUT', params: {id: null}},
})
});
//UidTags Services
myControllerModule.factory('UidTagsFactory', function ($resource) {
return $resource('/mc/rest/uidtags/:id', {id: '@id'}, {
getAll: { method: 'GET', isArray: false, params: {id: null}},
create: { method: 'POST', params: {id: null}},
deleteIds: { method: 'POST', params: {id: 'delete'}},
update: { method: 'PUT', params: {id: null}},
})
});
//Resources Logs Services
myControllerModule.factory('ResourcesLogsFactory', function ($resource) {
return $resource('/mc/rest/resources/logs/:action', {}, {
getAll: { method: 'GET', isArray: false },
purge: { method: 'PUT', isArray: false },
delete: { method: 'POST', isArray: false, params: {action:'delete'} },
})
});
//MyController Settings Services
myControllerModule.factory('SettingsFactory', function ($resource) {
return $resource('/mc/rest/settings/:type', {}, {
getLocation: { method: 'GET', isArray: false, params: {type:'location'} },
saveLocation: { method: 'POST', params: {type:'location'} },
getController: { method: 'GET', isArray: false, params: {type:'controller'} },
saveController: { method: 'POST', params: {type:'controller'} },
getEmail: { method: 'GET', isArray: false, params: {type:'email'} },
saveEmail: { method: 'POST', params: {type:'email'} },
getPushbullet: { method: 'GET', isArray: false, params: {type:'pushbullet'} },
savePushbullet: { method: 'POST', params: {type:'pushbullet'} },
getTelegramBot: { method: 'GET', isArray: false, params: {type:'telegrambot'} },
saveTelegramBot: { method: 'POST', params: {type:'telegrambot'} },
getSms: { method: 'GET', isArray: false, params: {type:'sms'} },
saveSms: { method: 'POST', params: {type:'sms'} },
getMySensors: { method: 'GET', isArray: false, params: {type:'mySensors'} },
saveMySensors: { method: 'POST', params: {type:'mySensors'} },
getUnits: { method: 'GET', isArray: false, params: {type:'units'} },
saveUnits: { method: 'POST', params: {type:'units'} },
updateLanguage: { method: 'PUT', params: {type:'updateLanguage'} },
getMetrics: { method: 'GET', isArray: false, params: {type:'metricsGraph'} },
saveMetrics: { method: 'POST', params: {type:'metricsGraph'} },
getMetricsRetention: { method: 'GET', isArray: false, params: {type:'metricsRetention'} },
saveMetricsRetention: { method: 'POST', params: {type:'metricsRetention'} },
getMetricsEngine: { method: 'GET', isArray: false, params: {type:'metricsEngine'} },
saveMetricsEngine: { method: 'POST', params: {type:'metricsEngine'} },
getUserSettings: { method: 'GET', isArray: false, params: {type:'userSettings'} },
saveUserSettings: { method: 'POST', params: {type:'userSettings'} },
getMqttBroker: { method: 'GET', isArray: false, params: {type:'mqttBroker'} },
saveMqttBroker: { method: 'POST', params: {type:'mqttBroker'} },
getSystemJobs: { method: 'GET', isArray: false, params: {type:'systemJobs'} },
saveSystemJobs: { method: 'POST', params: {type:'systemJobs'} },
getHtmlAdditionalHeaders: { method: 'GET', isArray: false, params: {type:'htmlAdditionalHeaders'} },
updateHtmlAdditionalHeaders: { method: 'POST', params: {type:'htmlAdditionalHeaders'} },
})
});
//MyController Status Services
myControllerModule.factory('StatusFactory', function ($resource) {
return $resource('/mc/rest/:type', {}, {
getOsStatus: { method: 'GET', params: {type:'osStatus'} },
getJvmStatus: { method: 'GET', params: {type:'jvmStatus'} },
runGarbageCollection: { method: 'PUT', params: {type:'runGarbageCollection'} },
getScriptEngines: { method: 'GET', isArray: true, params: {type:'scriptEngines'} },
getConfig: { method: 'GET', params: {type:'guiSettings'} },
getMcAbout: { method: 'GET', params: {type:'mcAbout'} },
getTimestamp: { method: 'GET', params: {type:'timestamp'} },
getMcServerLog: { method: 'GET', isArray: false, params: {type:'mcServerLogFile'} },
getStaticImageFile: { method: 'GET', isArray: false, params: {type:'imageFiles'} },
getStaticImageFilesList: { method: 'GET', isArray: true, params: {type:'imageFiles'} },
})
});
//Gateway Services
myControllerModule.factory('GatewaysFactory', function ($resource) {
return $resource('/mc/rest/gateways/:action/:gatewayId', {}, {
getAll: { method: 'GET', isArray: false, params: {action: null, gatewayId: null} },
get: { method: 'GET', params: {action: null} },
create: { method: 'POST', params: {action: null, gatewayId: null} },
update: { method: 'PUT', params: {action: null, gatewayId: null} },
delete: { method: 'POST', params: {action:'delete', gatewayId: null} },
enable: { method: 'POST', params: {action:'enable', gatewayId: null} },
disable: { method: 'POST', params: {action:'disable', gatewayId: null} },
reload: { method: 'POST', params: {action:'reload', gatewayId: null} },
discover: { method: 'POST', params: {action:'discover', gatewayId: null} },
statistics: {method: 'GET', params: {action:'statistics'} },
executeNodeInfoUpdate: { method: 'POST', params: {action:'executeNodeInfoUpdate', gatewayId: null} },
})
});
//ResourcesGroup Services
myControllerModule.factory('ResourcesGroupFactory', function ($resource) {
return $resource('/mc/rest/resources/group/:_id', {_id: '@_id'}, {
getAll: { method: 'GET', isArray: false, params: {_id: null} },
get: { method: 'GET'},
create: { method: 'POST', params: {_id: null}},
update: { method: 'PUT', params: {_id: null} },
deleteIds: { method: 'POST', params: {_id: 'delete'} },
turnOnIds: { method: 'POST', params: {_id: 'on'} },
turnOffIds: { method: 'POST', params: {_id: 'off'} },
})
});
//ResourcesGroupMap Services
myControllerModule.factory('ResourcesGroupMapFactory', function ($resource) {
return $resource('/mc/rest/resources/group/map/:id', {id: '@id'}, {
getAll: { method: 'GET', isArray: false, params: {id: null} },
get: { method: 'GET' },
create: { method: 'POST', params: {id: null}},
update: { method: 'PUT', params: {id: null} },
deleteIds: { method: 'POST', params: {id: 'delete'} },
})
});
//Read static files
myControllerModule.factory('ReadFileFactory', function ($resource) {
return $resource('/:locationName/:fileName', {}, {
getConfigFile: { method: 'GET', isArray: false, params: {locationName: '_configurations', fileName:'mycontroller-configs.json'} },
})
});
//Dashboard Services
myControllerModule.factory('DashboardFactory', function ($resource) {
return $resource('/mc/rest/dashboard/:id', {}, {
getAll: { method: 'GET', isArray: true},
get: { method: 'GET',isArray: false},
update: { method: 'PUT'},
delete: { method: 'DELETE'},
})
});
//Backup and restore services
myControllerModule.factory('BackupRestoreFactory', function ($resource) {
return $resource('/mc/rest/backup/:type', {}, {
getAll: { method: 'GET', isArray: false, params: {type: 'backupFiles'}},
backupNow: { method: 'PUT', params: {type: 'backupNow'}},
restore: { method: 'POST', params: {type: 'restore'}},
deleteIds: { method: 'POST', params: {type: 'delete'}},
getBackupSettings: { method: 'GET', params: {type: 'backupSettings'}},
updateBackupSettings: { method: 'PUT', params: {type: 'backupSettings'}},
})
});
//Rooms Services
myControllerModule.factory('RoomsFactory', function ($resource) {
return $resource('/mc/rest/rooms/:id', {id: '@id'}, {
getAll: { method: 'GET', isArray: false, params: {id: null} },
get: { method: 'GET' },
create: { method: 'POST', params: {id: null}},
update: { method: 'PUT', params: {id: null} },
deleteIds: { method: 'POST', params: {id: 'delete'} },
})
});
//Scripts Services
myControllerModule.factory('ScriptsFactory', function ($resource) {
return $resource('/mc/rest/scripts/:id', {id: '@id'}, {
getAll: { method: 'GET', isArray: false, params: {id: null} },
getAllLessInfo: { method: 'GET', isArray: true, params: {id: null, 'lessInfo':true} },
get: { method: 'GET', params: {id: 'get'}},
runNow: { method: 'GET', params: {id: 'runNow'}},
upload: { method: 'POST', params: {id: null} },
deleteIds: { method: 'POST', params: {id: 'delete'} },
})
});
//Templates Services
myControllerModule.factory('TemplatesFactory', function ($resource) {
return $resource('/mc/rest/templates/:id', {id: '@id'}, {
getAll: { method: 'GET', isArray: false, params: {id: null} },
getAllLessInfo: { method: 'GET', isArray: true, params: {id: null, 'lessInfo':true} },
get: { method: 'GET', params: {id: 'get'}},
getHtml: { method: 'GET', params: {id: 'getHtml'}},
upload: { method: 'POST', params: {id: null} },
deleteIds: { method: 'POST', params: {id: 'delete'} },
})
});
//Variables repository Services
myControllerModule.factory('VariablesRepositoryFactory', function ($resource) {
return $resource('/mc/rest/variables/:pid', {pid: '@id'}, {
getAll: { method: 'GET', isArray: false, params: {pid: null} },
get: { method: 'GET', params: {pid: 'get'}},
create: { method: 'POST', params: {pid: null} },
update: { method: 'PUT', params: {pid: null} },
deleteIds: { method: 'POST', params: {pid: 'delete'} },
})
});
//Resources Data Services
myControllerModule.factory('ResourcesDataFactory', function ($resource) {
return $resource('/mc/rest/resourcesdata/:id', {id: '@id'}, {
getAll: { method: 'GET', isArray: false, params: {id: null}},
create: { method: 'POST', params: {id: null}},
deleteIds: { method: 'POST', params: {id: 'delete'}},
enableIds: { method: 'POST', params: {id: 'enable'}},
disableIds: { method: 'POST', params: {id: 'disable'}},
get: { method: 'GET'},
update: { method: 'PUT', params: {id: null}},
})
});
//External Server Services
myControllerModule.factory('ExternalServersFactory', function ($resource) {
return $resource('/mc/rest/externalserver/:id', {id: '@id'}, {
getAll: { method: 'GET', isArray: false, params: {id: null}},
create: { method: 'POST', params: {id: null}},
deleteIds: { method: 'POST', params: {id: 'delete'}},
enableIds: { method: 'POST', params: {id: 'enable'}},
disableIds: { method: 'POST', params: {id: 'disable'}},
get: { method: 'GET'},
update: { method: 'PUT', params: {id: null}},
})
});
//Execute OS commands
myControllerModule.factory('OSCommandFactory', function ($resource) {
return $resource('/mc/rest/oscommands/execute', {}, {
execute: { method: 'POST'},
})
});

View File

@@ -0,0 +1,97 @@
/*
* Copyright 2015-2018 Jeeva Kandasamy (jkandasa@gmail.com)
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
myControllerModule.service('TopologyService', function($filter) {
this.tooltip = function tooltip(d) {
var status = [
$filter('translate')('NAME') + ': ' + d.item.name,
$filter('translate')('TYPE') + ': ' + $filter('translate')(d.item.type)
];
if(d.item.kind === "Node"){
status.push($filter('translate')('EUI') + ': ' + d.item.localId);
}
if(d.item.kind === "Sensor"){
status.push($filter('translate')('SENSOR_ID') + ': ' + d.item.localId);
}
if(d.item.kind === "Sensor" || d.item.kind === "SensorVariable"){
status.push($filter('translate')('SUB_TYPE') + ': ' + d.item.subType.locale);
}
if(d.item.kind === "Gateway" || d.item.kind === "Node"){
status.push($filter('translate')('STATUS') + ': ' + $filter('translate')(d.item.status.toUpperCase()));
}else if(d.item.kind === "SensorVariable"){
status.push($filter('translate')('STATUS') + ': ' + d.item.status);
}
return status;
};
this.addContextMenuOption = function(popup, text, data, callback) {
popup.append("p").text(text)
.on('click' , function() {callback(data);});
};
this.searchNode = function(svg, query) {
var nodes = svg.selectAll("g");
if (query != "") {
var selected = nodes.filter(function (d) {
return d.item.name != query;
});
selected.style("opacity", "0.2");
var links = svg.selectAll("line");
links.style("opacity", "0.2");
}
};
this.resetSearch = function(d3) {
// Display all topology nodes and links
d3.selectAll("g, line").transition()
.duration(2000)
.style("opacity", 1);
};
this.getSVG = function(d3) {
var graph = d3.select("kubernetes-topology-graph");
var svg = graph.select('svg');
return svg;
};
this.defaultElementDimensions = function() {
return { x: 0, y: 9, r: 17 };
};
this.getItemStatusClass = function(d) {
switch (d.item.status) {
case "Armed":
case "On":
case "ON":
case "Up":
case "Untripped":
return "success";
case "Armed":
case "OFF":
case "Off":
case "Tripped":
case "Down":
return "error";
}
};
});

View File

@@ -0,0 +1,50 @@
/*
* Copyright 2015-2018 Jeeva Kandasamy (jkandasa@gmail.com)
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// don't forget to declare this service module as a dependency in your main app constructor!
//http://js2.coffee/#coffee2js
//https://coderwall.com/p/r_bvhg/angular-ui-bootstrap-alert-service-for-angular-js
myControllerModule.factory('validationServices', function() {
var validationService = {};
//Validate isNumber
validationService.isNumber = function (value) {
if (isNaN(value)) {
return false;
}
return true;
};
//Validate isString
validationService.isString = function (value) {
if (isNaN(value)) {
return false;
}
return true;
};
//Validate isString
validationService.isEmpty = function (value) {
if (!value || value === "") {
return false;
}
return true;
};
return validationService;
});