From c478db455fd285830a35f45c67d7e5d87126e7e3 Mon Sep 17 00:00:00 2001 From: Rasika Perera Date: Sat, 25 Jul 2015 09:33:52 +0530 Subject: [PATCH] restoring previous errornous jaggery app --- .../jaggeryapps/iotserver/api/device-api.jag | 98 +++++-- .../iotserver/api/operation-api.jag | 31 +++ .../jaggeryapps/iotserver/api/policy-api.jag | 49 ++++ .../jaggeryapps/iotserver/api/stats-api.jag | 171 ++++++------ .../jaggeryapps/iotserver/api/user-api.jag | 13 +- .../jaggeryapps/iotserver/config/init.js | 2 +- .../jaggeryapps/iotserver/jaggery.conf | 22 +- .../iotserver/layouts/fluid-backup.hbs | 44 ++++ .../jaggeryapps/iotserver/layouts/fluid.hbs | 22 +- .../jaggeryapps/iotserver/lib/acs.jag | 10 +- .../jaggeryapps/iotserver/lib/fuse-router.js | 67 ++--- .../jaggeryapps/iotserver/lib/fuse.jag | 4 +- .../jaggeryapps/iotserver/lib/fuse.js | 58 +++-- .../iotserver/lib/handlebars-helpers.js | 63 ++--- .../iotserver/lib/less-rhino-1.7.5.js | 2 +- .../iotserver/modules/api-wrapper-util.js | 41 +++ .../iotserver/modules/constants.js | 4 +- .../jaggeryapps/iotserver/modules/device.js | 16 +- .../jaggeryapps/iotserver/modules/policy.js | 85 ++++++ .../jaggeryapps/iotserver/modules/user.js | 30 +++ .../jaggeryapps/iotserver/modules/util.js | 89 +++++++ .../jaggeryapps/iotserver/modules/utility.js | 50 +++- .../jaggeryapps/iotserver/pages/dashboard.hbs | 1 + .../iotserver/pages/devices/android.hbs | 2 +- .../iotserver/pages/devices/android_sense.hbs | 2 +- .../iotserver/pages/devices/arduino.hbs | 2 +- .../pages/devices/digital_display.hbs | 2 +- .../iotserver/pages/devices/firealarm.hbs | 2 +- .../iotserver/pages/devices/index.hbs | 2 +- .../iotserver/pages/devices/raspberrypi.hbs | 2 +- .../iotserver/pages/devices/sensebot.hbs | 2 +- .../iotserver/pages/devices/windows.hbs | 2 +- .../iotserver/pages/policies/add-policy.hbs | 9 + .../iotserver/pages/policies/index.hbs | 21 ++ .../repository/jaggeryapps/iotserver/test.jag | 12 + .../jaggeryapps/iotserver/test/device-spec.js | 100 +++++++ .../jaggeryapps/iotserver/test/user-spec.js | 88 +++++++ .../jaggeryapps/iotserver/token.jag | 4 + .../iotserver/units/analytics/analytics.hbs | 3 + .../units/analytics/public/js/graph_util.js | 82 ++++-- .../public/js/graphs/cpu_temperature_graph.js | 70 +++++ .../units/{devices => }/android/android.hbs | 0 .../iotserver/units/android/android.js | 4 + .../units/{devices => }/android/android.json | 0 .../android/public/images/android-thumb.png | Bin .../android/public/images/android.png | Bin .../{devices => }/android/public/store.json | 0 .../android_sense/android_sense.hbs | 0 .../units/android_sense/android_sense.js | 4 + .../android_sense/android_sense.json | 0 .../public/images/android_sense-thumb.png | Bin .../public/images/android_sense.png | Bin .../android_sense/public/store.json | 0 .../iotserver/units/appbar/appbar.hbs | 4 +- .../iotserver/units/appbar/appbar.js | 9 +- .../units/{devices => }/arduino/arduino.hbs | 0 .../iotserver/units/arduino/arduino.js | 4 + .../units/{devices => }/arduino/arduino.json | 0 .../arduino/public/images/arduino-thumb.png | Bin .../arduino/public/images/arduino.png | Bin .../{devices => }/arduino/public/store.json | 0 .../device-detail/public/js/device-detail.js | 39 +++ .../units/device-listing/device-listing.hbs | 4 +- .../public/js/device-listing.js | 33 +-- .../public/templates/device-listing.hbs | 6 +- .../units/devices/android/android.js | 4 - .../devices/android_sense/android_sense.js | 4 - .../units/devices/arduino/arduino.js | 4 - .../units/devices/firealarm/firealarm.hbs | 90 ------- .../digital_display/digital_display.hbs | 0 .../digital_display/digital_display.js | 0 .../digital_display/digital_display.json | 0 .../public/images/digital_display-thumb.png | Bin .../public/images/digital_display.png | Bin .../digital_display/public/store.json | 0 .../iotserver/units/firealarm/firealarm.hbs | 215 ++++++++++++++++ .../units/firealarm/firealarm.hbs.save | 213 +++++++++++++++ .../{devices => }/firealarm/firealarm.js | 0 .../{devices => }/firealarm/firealarm.json | 0 .../public/images/firealarm-thumb.png | Bin .../firealarm/public/images/firealarm.png | Bin .../public/images/schematicsGuide.png | Bin 0 -> 154917 bytes .../units/firealarm/public/js/firealarm.js | 104 ++++++++ .../{devices => }/firealarm/public/store.json | 0 .../jaggeryapps/iotserver/units/logo/logo.hbs | 2 +- .../units/policy-create/policy-create.hbs | 243 ++++++++++++++++++ .../units/policy-create/policy-create.js | 10 + .../units/policy-create/policy-create.json | 3 + .../policy-create/public/js/policy-create.js | 156 +++++++++++ .../units/policy-detail/policy-detail.hbs | 201 +++++++++++++++ .../units/policy-detail/policy-detail.js | 58 +++++ .../policy-detail.json} | 0 .../policy-detail/public/js/policy-detail.js | 39 +++ .../units/policy-listing/policy-listing.hbs | 80 ++++++ .../units/policy-listing/policy-listing.js | 18 ++ .../units/policy-listing/policy-listing.json | 5 + .../public/js/policy-listing.js | 131 ++++++++++ .../public/images/raspberrypi-thumb.png | Bin .../raspberrypi/public/images/raspberrypi.png | Bin .../raspberrypi/public/store.json | 0 .../{devices => }/raspberrypi/raspberrypi.hbs | 0 .../{devices => }/raspberrypi/raspberrypi.js | 0 .../raspberrypi.json} | 0 .../public/images/schematicsGuide.png | Bin .../sensebot/public/images/sensebot-thumb.png | Bin .../sensebot/public/images/sensebot.png | Bin .../{devices => }/sensebot/public/store.json | 0 .../units/{devices => }/sensebot/sensebot.hbs | 0 .../units/{devices => }/sensebot/sensebot.js | 0 .../sensebot.json} | 0 .../public/css/daterangepicker.css | 0 .../sensebot_nologin/public/css/nv.d3.css | 0 .../public/images/bulb-off.png | Bin .../public/images/bulb-on.png | Bin .../sensebot_nologin/public/images/fan.png | Bin .../sensebot_nologin/public/images/temp.png | Bin .../sensebot_nologin/public/js/bulb.js | 0 .../public/js/cumulativelinechart.js | 0 .../sensebot_nologin/public/js/d3.min.js | 0 .../sensebot_nologin/public/js/date-range.js | 0 .../public/js/discretebarchart.js | 0 .../sensebot_nologin/public/js/graph_util.js | 0 .../public/js/jquery.daterangepicker.js | 2 +- .../sensebot_nologin/public/js/light_graph.js | 0 .../public/js/linewithfocuschart.js | 0 .../sensebot_nologin/public/js/moment.min.js | 0 .../public/js/motion_graph.js | 0 .../sensebot_nologin/public/js/nv.d3.js | 0 .../sensebot_nologin/public/js/sonar_graph.js | 0 .../public/js/stream_layers.js | 0 .../public/js/temperature_graph.js | 0 .../sensebot_nologin/sensebot_nologin.hbs | 0 .../sensebot_nologin/sensebot_nologin.js | 0 .../sensebot_nologin.json} | 0 .../iotserver/units/showcase/showcase.hbs | 55 ++-- .../public/templates/store-listing.hbs | 2 +- .../units/theme/public/css/custom-theme.css | 1 + .../iotserver/units/theme/public/css/main.css | 53 ++++ .../iotserver/units/theme/theme.hbs | 10 +- .../windows/public/images/windows-thumb.png | Bin .../windows/public/images/windows.png | Bin .../{devices => }/windows/public/store.json | 0 .../units/{devices => }/windows/windows.hbs | 0 .../units/{devices => }/windows/windows.js | 0 .../iotserver/units/windows/windows.json | 3 + 145 files changed, 2743 insertions(+), 449 deletions(-) create mode 100644 modules/distribution/src/repository/jaggeryapps/iotserver/api/operation-api.jag create mode 100644 modules/distribution/src/repository/jaggeryapps/iotserver/api/policy-api.jag create mode 100644 modules/distribution/src/repository/jaggeryapps/iotserver/layouts/fluid-backup.hbs create mode 100644 modules/distribution/src/repository/jaggeryapps/iotserver/modules/api-wrapper-util.js create mode 100644 modules/distribution/src/repository/jaggeryapps/iotserver/modules/policy.js create mode 100644 modules/distribution/src/repository/jaggeryapps/iotserver/modules/util.js create mode 100644 modules/distribution/src/repository/jaggeryapps/iotserver/pages/policies/add-policy.hbs create mode 100644 modules/distribution/src/repository/jaggeryapps/iotserver/pages/policies/index.hbs create mode 100644 modules/distribution/src/repository/jaggeryapps/iotserver/test.jag create mode 100644 modules/distribution/src/repository/jaggeryapps/iotserver/test/device-spec.js create mode 100644 modules/distribution/src/repository/jaggeryapps/iotserver/test/user-spec.js create mode 100644 modules/distribution/src/repository/jaggeryapps/iotserver/token.jag create mode 100644 modules/distribution/src/repository/jaggeryapps/iotserver/units/analytics/public/js/graphs/cpu_temperature_graph.js rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/android/android.hbs (100%) create mode 100644 modules/distribution/src/repository/jaggeryapps/iotserver/units/android/android.js rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/android/android.json (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/android/public/images/android-thumb.png (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/android/public/images/android.png (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/android/public/store.json (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/android_sense/android_sense.hbs (100%) create mode 100644 modules/distribution/src/repository/jaggeryapps/iotserver/units/android_sense/android_sense.js rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/android_sense/android_sense.json (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/android_sense/public/images/android_sense-thumb.png (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/android_sense/public/images/android_sense.png (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/android_sense/public/store.json (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/arduino/arduino.hbs (100%) create mode 100644 modules/distribution/src/repository/jaggeryapps/iotserver/units/arduino/arduino.js rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/arduino/arduino.json (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/arduino/public/images/arduino-thumb.png (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/arduino/public/images/arduino.png (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/arduino/public/store.json (100%) delete mode 100644 modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android/android.js delete mode 100644 modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android_sense/android_sense.js delete mode 100644 modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/arduino/arduino.js delete mode 100644 modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/firealarm/firealarm.hbs rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/digital_display/digital_display.hbs (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/digital_display/digital_display.js (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/digital_display/digital_display.json (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/digital_display/public/images/digital_display-thumb.png (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/digital_display/public/images/digital_display.png (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/digital_display/public/store.json (100%) create mode 100644 modules/distribution/src/repository/jaggeryapps/iotserver/units/firealarm/firealarm.hbs create mode 100644 modules/distribution/src/repository/jaggeryapps/iotserver/units/firealarm/firealarm.hbs.save rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/firealarm/firealarm.js (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/firealarm/firealarm.json (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/firealarm/public/images/firealarm-thumb.png (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/firealarm/public/images/firealarm.png (100%) create mode 100644 modules/distribution/src/repository/jaggeryapps/iotserver/units/firealarm/public/images/schematicsGuide.png create mode 100644 modules/distribution/src/repository/jaggeryapps/iotserver/units/firealarm/public/js/firealarm.js rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/firealarm/public/store.json (100%) create mode 100644 modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-create/policy-create.hbs create mode 100644 modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-create/policy-create.js create mode 100644 modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-create/policy-create.json create mode 100644 modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-create/public/js/policy-create.js create mode 100644 modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-detail/policy-detail.hbs create mode 100644 modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-detail/policy-detail.js rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices/raspberrypi/raspberrypi.json => policy-detail/policy-detail.json} (100%) create mode 100644 modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-listing/policy-listing.hbs create mode 100644 modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-listing/policy-listing.js create mode 100644 modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-listing/policy-listing.json create mode 100644 modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-listing/public/js/policy-listing.js rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/raspberrypi/public/images/raspberrypi-thumb.png (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/raspberrypi/public/images/raspberrypi.png (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/raspberrypi/public/store.json (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/raspberrypi/raspberrypi.hbs (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/raspberrypi/raspberrypi.js (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices/sensebot/sensebot.json => raspberrypi/raspberrypi.json} (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/sensebot/public/images/schematicsGuide.png (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/sensebot/public/images/sensebot-thumb.png (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/sensebot/public/images/sensebot.png (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/sensebot/public/store.json (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/sensebot/sensebot.hbs (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/sensebot/sensebot.js (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices/sensebot_nologin/sensebot_nologin.json => sensebot/sensebot.json} (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/sensebot_nologin/public/css/daterangepicker.css (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/sensebot_nologin/public/css/nv.d3.css (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/sensebot_nologin/public/images/bulb-off.png (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/sensebot_nologin/public/images/bulb-on.png (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/sensebot_nologin/public/images/fan.png (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/sensebot_nologin/public/images/temp.png (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/sensebot_nologin/public/js/bulb.js (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/sensebot_nologin/public/js/cumulativelinechart.js (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/sensebot_nologin/public/js/d3.min.js (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/sensebot_nologin/public/js/date-range.js (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/sensebot_nologin/public/js/discretebarchart.js (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/sensebot_nologin/public/js/graph_util.js (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/sensebot_nologin/public/js/jquery.daterangepicker.js (96%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/sensebot_nologin/public/js/light_graph.js (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/sensebot_nologin/public/js/linewithfocuschart.js (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/sensebot_nologin/public/js/moment.min.js (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/sensebot_nologin/public/js/motion_graph.js (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/sensebot_nologin/public/js/nv.d3.js (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/sensebot_nologin/public/js/sonar_graph.js (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/sensebot_nologin/public/js/stream_layers.js (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/sensebot_nologin/public/js/temperature_graph.js (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/sensebot_nologin/sensebot_nologin.hbs (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/sensebot_nologin/sensebot_nologin.js (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices/windows/windows.json => sensebot_nologin/sensebot_nologin.json} (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/windows/public/images/windows-thumb.png (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/windows/public/images/windows.png (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/windows/public/store.json (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/windows/windows.hbs (100%) rename modules/distribution/src/repository/jaggeryapps/iotserver/units/{devices => }/windows/windows.js (100%) create mode 100644 modules/distribution/src/repository/jaggeryapps/iotserver/units/windows/windows.json diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/api/device-api.jag b/modules/distribution/src/repository/jaggeryapps/iotserver/api/device-api.jag index 34eadba2..5bd5fb95 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/api/device-api.jag +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/api/device-api.jag @@ -16,7 +16,6 @@ * specific language governing permissions and limitations * under the License. */ - var uri = request.getRequestURI(); var uriMatcher = new URIMatcher(String(uri)); @@ -33,27 +32,85 @@ var carbonHttpsServletTransport = carbon.server.address('https'); var result; -if (uriMatcher.match("/{context}/api/device/sketch/download")) { - sketchType = request.getParameter("sketchType"); - deviceType = request.getParameter("deviceType"); +if (uriMatcher.match("/{context}/api/device/sketch/download/{downloadId}")) { + downloadId = uriMatcher.elements().downloadId; + //Just download the already created zip archive + var CarbonUtils = Packages.org.wso2.carbon.utils.CarbonUtils; + var sketchFolder = "repository/resources/sketches"; + var archivesPath = "file://"+CarbonUtils.getCarbonHome() + "/" + sketchFolder + "/archives/" + downloadId + ".zip"; + var zipFile = new File(archivesPath); + response.addHeader('Content-type', "application/zip, application/octet-stream"); + response.addHeader('Cache-Control', 'public,max-age=12960000'); + response.addHeader("Content-Disposition", "attachment; filename=\"" + downloadId + ".zip\""); + + try { + zipFile.open('r'); + var stream = zipFile.getStream(); + print(stream); + }catch(err){ + + }finally{ + if(zipFile!=null) { + zipFile.close(); + } + } + +} else if (uriMatcher.match("/{context}/api/device/sketch/download")) { + //Create a new zip archive and register user calling endpoint + + /* This should match with $CARBON_HOME/repository/resources/sketches/{sketchType} */ + sketchType = request.getParameter("sketchType"); + /* This should be registered device type of the CDMF(Connected Device Management Framework) */ + deviceType = request.getParameter("deviceType"); + + if (!sketchType) { + log.error("Sketch Type is empty!"); + // http status code 400 refers to - Bad request. + result = 400; + } else { + var user = session.get(constants.USER_SESSION_KEY); + + if (!user) { + response.sendRedirect(dcProps.appContext + "login?#login-required"); + exit(); + } + + //URL: https://localhost:9443/{deviceType}/download?owner={username} + deviceManagerService = carbonHttpsServletTransport + "/" + deviceType + "/manager"; + + sketchDownloadEndPoint = deviceManagerService + "/device/" + sketchType + "/download"; + response.sendRedirect(sketchDownloadEndPoint + "?owner=" + user.username); + exit();//stop execution + + } +} else if (uriMatcher.match("/{context}/api/device/sketch/generate_link")) { + + var contents = request.getContent(); + sketchType = contents.sketchType; + deviceType = contents.deviceType; + generateLink = contents.generateLink; if (!sketchType) { - log.error("Sketch Type is empty"); - } - - var user = session.get(constants.USER_SESSION_KEY); - if (!user) { - response.sendRedirect(dcProps.appContext + "login?#login-required"); - exit(); + log.error("Sketch Type is empty!"); + // http status code 400 refers to - Bad request. + result = 400; + } else { + var user = session.get(constants.USER_SESSION_KEY); + + if (!user) { + result = 403; + }else { + //URL: https://localhost:9443/{deviceType}/download?owner={username} + deviceManagerService = carbonHttpsServletTransport + "/" + deviceType + "/manager"; + + sketchGenerateLinkEndPoint = deviceManagerService + "/device/" + sketchType + "/generate_link"; + var fileId = get(sketchGenerateLinkEndPoint + "?owner=" + user.username, null, "text"); + result = carbonHttpsServletTransport + constants.WEB_APP_CONTEXT + "/api/device/sketch/download/" + fileId.data; + } } - //URL: https://localhost:9443/{deviceType}/download?owner={username} - deviceManagerService = carbonHttpsServletTransport + "/" + deviceType + "/manager"; - sketchDownloadEndPoint = deviceManagerService + "/device/" + sketchType + "/download"; - response.sendRedirect(sketchDownloadEndPoint + "?owner=" + user.username); - exit();//stop execution - } else if (uriMatcher.match("/{context}/api/devices/all")) { + var user = session.get(constants.USER_SESSION_KEY); if (!user) { response.sendRedirect(dcProps.appContext + "login?#login-required"); @@ -66,7 +123,12 @@ if (uriMatcher.match("/{context}/api/device/sketch/download")) { var data = {}; //XMLHTTPRequest's GET - result = get(listAllDevicesEndPoint, data, "json"); + try { + result = get(listAllDevicesEndPoint, data, "json"); + }catch(err){ + log.error("Error occured while retrieveing all devices with username: "+user.username); + result=[]; + } } else if (uriMatcher.match("/{context}/api/devices/types")) { diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/api/operation-api.jag b/modules/distribution/src/repository/jaggeryapps/iotserver/api/operation-api.jag new file mode 100644 index 00000000..4fa85bfc --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/api/operation-api.jag @@ -0,0 +1,31 @@ +<% +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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. + */ + +var uri = request.getRequestURI(); +var uriMatcher = new URIMatcher(String(uri)); + +var log = new Log("api/operation-api.jag"); + +var deviceModule = require("/modules/device.js").deviceModule; + +if (uriMatcher.match("/{context}/api/operation")) { + payload = request.getContent(); + result = deviceModule.performOperation(payload.devices, payload.operation); +} +%> \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/api/policy-api.jag b/modules/distribution/src/repository/jaggeryapps/iotserver/api/policy-api.jag new file mode 100644 index 00000000..5615c877 --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/api/policy-api.jag @@ -0,0 +1,49 @@ +<% +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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. + */ + +var uri = request.getRequestURI(); +var uriMatcher = new URIMatcher(String(uri)); + +var log = new Log("api/policy-api.jag"); + +var constants = require("/modules/constants.js"); +var dcProps = require('/config/dc-props.js').config(); +var policyModule = require("/modules/policy.js").policyModule; + +var result; +if (uriMatcher.match("/{context}/api/policies/update")) { + payload = request.getContent(); + policyModule.updatePolicyPriorities(payload); +} else if (uriMatcher.match("/{context}/api/policies/{id}/delete")) { + elements = uriMatcher.elements(); + policyId = elements.id; + try { + result = policyModule.deletePolicy(policyId); + } catch (e) { + log.error("Exception occurred while trying to delete policy for id:" + policyId, e); + // http status code 500 refers to - Internal Server Error. + result = 500; + } +} + +// returning the result. +if (result) { + response.content = result; +} +%> \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/api/stats-api.jag b/modules/distribution/src/repository/jaggeryapps/iotserver/api/stats-api.jag index 95d29d05..9f3fa5fb 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/api/stats-api.jag +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/api/stats-api.jag @@ -31,118 +31,111 @@ var statsClient = new Packages.org.wso2.carbon.device.mgt.iot.common.analytics.s if (uriMatcher.match("/{context}/api/stats")) { - deviceId = request.getParameter("deviceId"); - deviceType = request.getParameter("deviceType"); - from = request.getParameter("from"); - to = request.getParameter("to"); - - user = session.get(constants.USER_SESSION_KEY); - if (!user) { - response.sendRedirect(dcProps.appContext + "login?#login-required"); - exit(); - } - - log.info("deviceId : " + deviceId + " from : " + from + " to : " + to); - - switch (deviceType){ - case "firealarm": - result = getFireAlarmData(user.username, deviceId, from, to); - break; - case "sensebot": - result = getSensebotData(user.username, deviceId, from, to); - break; - case "arduino": - result = getArduinoData(user.username, deviceId, from, to); - break; - case "digital_display": - result = getDigitalDisplayData(user.username, deviceId, from, to); - break; - case "android_sense": - result = getAndroidSenseData(user.username, deviceId, from, to); - break; - case "raspberrypi": - result = getDigitalDisplayData(user.username, deviceId, from, to); - break; - default: - result = new Object(); - } + deviceId = request.getParameter("deviceId"); + deviceType = request.getParameter("deviceType"); + from = request.getParameter("from"); + to = request.getParameter("to"); + + user = session.get(constants.USER_SESSION_KEY); + if (!user) { + response.sendRedirect(dcProps.appContext + "login?#login-required"); + exit(); + } + + log.info("deviceId : " + deviceId + " from : " + from + " to : " + to); + + switch (deviceType) { + case "firealarm": + result = getFireAlarmData(user.username, deviceId, from, to); + break; + case "sensebot": + result = getSensebotData(user.username, deviceId, from, to); + break; + case "arduino": + result = getArduinoData(user.username, deviceId, from, to); + break; + case "digital_display": + result = getDigitalDisplayData(user.username, deviceId, from, to); + break; + case "android_sense": + result = getAndroidSenseData(user.username, deviceId, from, to); + break; + case "raspberrypi": + result = getDigitalDisplayData(user.username, deviceId, from, to); + break; + default: + result = new Object(); + } } // returning the result. if (result) { - print(result); + print(result); } -function getFireAlarmData(user, deviceId, from, to){ - result = new Object(); - result['temperatureData'] = getSensorData("DEVICE_TEMPERATURE_SUMMARY","TEMPERATURE",user, deviceId, from, to); - result['fanData'] = getSensorData("DEVICE_FAN_USAGE_SUMMARY","status",user, deviceId, from, to); - result['bulbData'] = getSensorData("DEVICE_BULB_USAGE_SUMMARY","status",user, deviceId, from, to); - return result; +function getFireAlarmData(user, deviceId, from, to) { + result = new Object(); + result['cpuTemperatureData'] = getSensorData("DEVICE_CPU_TEMPERATURE_SUMMARY", "TEMPERATURE", user, deviceId, from, to); + result['temperatureData'] = getSensorData("DEVICE_TEMPERATURE_SUMMARY", "TEMPERATURE", user, deviceId, from, to); + result['fanData'] = getSensorData("DEVICE_FAN_USAGE_SUMMARY", "status", user, deviceId, from, to); + result['bulbData'] = getSensorData("DEVICE_BULB_USAGE_SUMMARY", "status", user, deviceId, from, to); + return result; } -function getSensebotData(user, deviceId, from, to){ - result = new Object(); - result['sonarData'] = getSensorData("SONAR_SENSOR_SUMMARY","sonar",user, deviceId, from, to); - result['motionData'] = getSensorData("PIR_MOTION_SENSOR_SUMMARY","motion",user, deviceId, from, to); - result['lightData'] = getSensorData("LDR_LIGHT_SENSOR_SUMMARY","light",user, deviceId, from, to); - result['temperatureData'] = getSensorData("DEVICE_TEMPERATURE_SUMMARY","TEMPERATURE",user, deviceId, from, to); - return result; +function getSensebotData(user, deviceId, from, to) { + result = new Object(); + result['sonarData'] = getSensorData("SONAR_SENSOR_SUMMARY", "sonar", user, deviceId, from, to); + result['motionData'] = getSensorData("PIR_MOTION_SENSOR_SUMMARY", "motion", user, deviceId, from, to); + result['lightData'] = getSensorData("LDR_LIGHT_SENSOR_SUMMARY", "light", user, deviceId, from, to); + result['temperatureData'] = getSensorData("DEVICE_TEMPERATURE_SUMMARY", "TEMPERATURE", user, deviceId, from, to); + return result; } -function getArduinoData(user, deviceId, from, to){ - result = new Object(); - result['temperatureData'] = getSensorData("DEVICE_TEMPERATURE_SUMMARY","TEMPERATURE",user, deviceId, from, to); - return result; +function getArduinoData(user, deviceId, from, to) { + result = new Object(); + result['temperatureData'] = getSensorData("DEVICE_TEMPERATURE_SUMMARY", "TEMPERATURE", user, deviceId, from, to); + return result; } -function getDigitalDisplayData(user, deviceId, from, to){ - result = new Object(); - result['ramData'] = getSensorData("RAM_USAGE_SUMMARY","motion",user, deviceId, from, to); - result['cpuData'] = getSensorData("CPU_LOAD_SUMMARY","light",user, deviceId, from, to); - result['temperatureData'] = getSensorData("DEVICE_TEMPERATURE_SUMMARY","TEMPERATURE",user, deviceId, from, to); - return result; +function getAndroidSenseData(user, deviceId, from, to) { + result = new Object(); + result['ramData'] = getSensorData("RAM_USAGE_SUMMARY", "motion", user, deviceId, from, to); + result['cpuData'] = getSensorData("CPU_LOAD_SUMMARY", "light", user, deviceId, from, to); + result['temperatureData'] = getSensorData("DEVICE_TEMPERATURE_SUMMARY", "TEMPERATURE", user, deviceId, from, to); + result['motionData'] = getSensorData("PIR_MOTION_SENSOR_SUMMARY", "motion", user, deviceId, from, to); + return result; } -function getAndroidSenseData(user, deviceId, from, to){ - result = new Object(); - result['ramData'] = getSensorData("RAM_USAGE_SUMMARY","motion",user, deviceId, from, to); - result['cpuData'] = getSensorData("CPU_LOAD_SUMMARY","light",user, deviceId, from, to); - result['temperatureData'] = getSensorData("DEVICE_TEMPERATURE_SUMMARY","TEMPERATURE",user, deviceId, from, to); - result['motionData'] = getSensorData("PIR_MOTION_SENSOR_SUMMARY","motion",user, deviceId, from, to); - return result; -} - -function getDigitalDisplayData(user, deviceId, from, to){ - result = new Object(); - result['ramData'] = getSensorData("RAM_USAGE_SUMMARY","motion",user, deviceId, from, to); - result['cpuData'] = getSensorData("CPU_LOAD_SUMMARY","light",user, deviceId, from, to); - result['temperatureData'] = getSensorData("DEVICE_TEMPERATURE_SUMMARY","TEMPERATURE",user, deviceId, from, to); - return result; +function getDigitalDisplayData(user, deviceId, from, to) { + result = new Object(); + result['ramData'] = getSensorData("RAM_USAGE_SUMMARY", "motion", user, deviceId, from, to); + result['cpuData'] = getSensorData("CPU_LOAD_SUMMARY", "light", user, deviceId, from, to); + result['cpuTemperatureData'] = getSensorData("DEVICE_CPU_TEMPERATURE_SUMMARY", "TEMPERATURE", user, deviceId, from, to); + return result; } function getSensorData(table, column, user, deviceId, from, to) { - var fetchedData = null; + var fetchedData = null; - try { - fetchedData = statsClient.getDeviceStats(table, column, user, deviceId, from, to); - }catch(error){ - log.info(error); - } + try { + fetchedData = statsClient.getDeviceStats(table, column, user, deviceId, from, to); + } catch (error) { + log.error(error); + } - var sensorData = []; + var sensorData = []; - if(fetchedData==null) return []; + if (fetchedData == null) return []; - for (var i = 0; i < fetchedData.size(); i++) { - sensorData.push({ - time: fetchedData.get(i).getTime(), - value: fetchedData.get(i).getValue() - }); - } + for (var i = 0; i < fetchedData.size(); i++) { + sensorData.push({ + time: fetchedData.get(i).getTime(), + value: fetchedData.get(i).getValue() + }); + } - return sensorData; + return sensorData; } %> \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/api/user-api.jag b/modules/distribution/src/repository/jaggeryapps/iotserver/api/user-api.jag index 8586730a..1bf40351 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/api/user-api.jag +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/api/user-api.jag @@ -25,7 +25,9 @@ var log = new Log("api/user-api.jag"); var constants = require("/modules/constants.js"); var dcProps = require('/config/dc-props.js').config(); var userModule = require("/modules/user.js").userModule; +var deviceModule = require("/modules/device.js").deviceModule; var utility = require("/modules/utility.js").utility; +var deviceManagementService = utility.getDeviceManagementService(); var result; @@ -40,7 +42,14 @@ if (uriMatcher.match("/{context}/api/user/login/")) { if (log.isDebugEnabled()) { log.debug("User Logged In : " + user); } - response.sendRedirect(constants.WEB_APP_CONTEXT); + var hasDevcies = (deviceManagementService.getDevicesOfUser(username).size() >= 1); + + if(hasDevcies){ + response.sendRedirect(constants.WEB_APP_CONTEXT+"/devices"); + }else{ + response.sendRedirect(constants.WEB_APP_CONTEXT); + } + }, function () { response.sendRedirect(dcProps.appContext + "login?#auth-failed"); }); @@ -69,7 +78,7 @@ if (uriMatcher.match("/{context}/api/user/login/")) { } else { userRoles = String(addUserFormData.userRoles).split(","); } - + userRoles="deviceRole, deviceUser"; try { result = userModule.registerUser(username, firstname, lastname, emailAddress, password, userRoles); diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/config/init.js b/modules/distribution/src/repository/jaggeryapps/iotserver/config/init.js index d492ae79..5fd208f2 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/config/init.js +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/config/init.js @@ -25,4 +25,4 @@ var carbonServer = new carbonModule.server.Server({ application.put("carbonServer", carbonServer); var userModule = require("/modules/user.js").userModule; var utility = require("/modules/utility.js").utility; -utility.insertAppPermissions(userModule, "init"); \ No newline at end of file +utility.insertAppPermissions(userModule, "init"); diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/jaggery.conf b/modules/distribution/src/repository/jaggeryapps/iotserver/jaggery.conf index 9d723c35..420fe87e 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/jaggery.conf +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/jaggery.conf @@ -3,17 +3,25 @@ "logLevel": "info", "initScripts": ["/config/init.js"], "urlMappings": [ + { + "url" : "/testb/*", + "path" : "test.jag" + }, { "url" : "/test/*", "path" : "test/testExecutor.jag" }, { - "url": "/api/device/*", - "path": "/api/device-api.jag" + "url": "/api/device/*", + "path": "/api/device-api.jag" + }, + { + "url": "/api/devices/*", + "path": "/api/device-api.jag" }, { - "url": "/api/devices/*", - "path": "/api/device-api.jag" + "url": "/api/operation/*", + "path": "/api/operation-api.jag" }, { "url": "/api/user/*", @@ -27,6 +35,10 @@ "url": "/api/stats/*", "path": "/api/stats-api.jag" }, + { + "url": "/api/policies/*", + "path": "/api/policy-api.jag" + }, { "url": "/sso/login", "path": "/lib/login.jag" @@ -44,4 +56,4 @@ "path": "/lib/fuse.jag" } ] -} \ No newline at end of file +} diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/layouts/fluid-backup.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/layouts/fluid-backup.hbs new file mode 100644 index 00000000..6c9436ce --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/layouts/fluid-backup.hbs @@ -0,0 +1,44 @@ + + + + + {{ defineZone "title"}} + {{ defineZone "topCss"}} + + + + + +
+
+
+ {{ defineZone "content"}} +
+
+ +
+ + + + + diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/layouts/fluid.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/layouts/fluid.hbs index 3065855a..6cedfaad 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/layouts/fluid.hbs +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/layouts/fluid.hbs @@ -1,14 +1,15 @@ - - - - - - - {{ defineZone "title"}} - {{ defineZone "topLibCss"}} - {{ defineZone "topCss"}} - {{ defineZone "topJs"}} + + + + + + {{defineZone "favicon"}} + + {{ defineZone "title"}} + + {{ defineZone "topLibCss"}} + {{ defineZone "topCss"}}
@@ -32,6 +33,7 @@ {{ defineZone "body"}} {{ defineZone "footer"}}
+ {{ defineZone "bottomjquery" }} {{ defineZone "bottomLibJs" }} {{ defineZone "bottomJs" }} diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/lib/acs.jag b/modules/distribution/src/repository/jaggeryapps/iotserver/lib/acs.jag index 147c20a2..8aae7961 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/lib/acs.jag +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/lib/acs.jag @@ -22,6 +22,8 @@ var sso = require('/modules/sso.js').sso; var constants = require('/modules/constants.js'); var carbonModule = require("carbon"); var log = new Log(); +var apiWrapperUtil = require("/modules/api-wrapper-util.js").apiWrapperUtil; +var userModule = require("/modules/user.js").userModule; var keyStoreParams = { keyStoreName: dataConfig.ssoConfiguration.keyStoreName, keyStorePassword: dataConfig.ssoConfiguration.keyStorePassword, @@ -31,14 +33,18 @@ sso.configure(dataConfig.ssoConfiguration.issuer, dataConfig.ssoConfiguration.appName, keyStoreParams, dataConfig.ssoConfiguration.identityProviderURL); sso.acs( - function(loggedInUser) { + function(loggedInUser, samlResponse) { var carbonUser = carbonModule.server.tenantUser(loggedInUser); session.put(constants.USER_SESSION_KEY, carbonUser); var username = carbonUser.username; if(log.isDebugEnabled()){ log.debug("User logged in: "+username); } - response.sendRedirect(dataConfig.appContext); + var permissions = userModule.getUIPermissions(); + if (permissions.DASHBOARD_VIEW){ + apiWrapperUtil.setupAccessTokenPair("saml", samlResponse); + response.sendRedirect(dataConfig.appContext + "/device-mgt"); + } }, function() { if(log.isDebugEnabled()){ log.debug("User logged out"); diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/lib/fuse-router.js b/modules/distribution/src/repository/jaggeryapps/iotserver/lib/fuse-router.js index 6ab63dc1..e9e2b793 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/lib/fuse-router.js +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/lib/fuse-router.js @@ -82,41 +82,10 @@ var route; }; var renderStatic = function (unit, path) { - var unitModel = null; - var unitName = ""; - var parts = (unit + path).split("/"); - - //'unitName' name can be "unitA" or "categoryA/unitA" or "categoryA/categoryAb/unitB"...etc - //incrementally trying to resolve a unit using url path parts. - for (var i = 0; i < parts.length; i++) { - - if (unitName == "") { - unitName = parts[i]; - } else { - unitName += "/" + parts[i]; - } - - try { - var model = fuse.getUnitDefinition(unitName); - if (model) { - unitModel = { - name: model.name, - path: parts.splice(i + 1).join("/") - }; - break; - } - } catch (err) { - //unit not found, ignore error - } + if (log.isDebugEnabled()) { + log.debug('[' + requestId + '] for unit "' + unit + '" a request received for a static file "' + path + '"'); } - - if (unitModel == null) { - log.error("unit `"+unit+"` not found!"); - return false; - } - - var staticFile = fuse.getFile(unitModel.name, 'public' + "/" + unitModel.path); - + var staticFile = fuse.getFile(unit, 'public' + path); if (staticFile.isExists() && !staticFile.isDirectory()) { response.addHeader('Content-type', getMime(path)); response.addHeader('Cache-Control', 'public,max-age=12960000'); @@ -139,7 +108,7 @@ var route; if (jagFile.isExists()) { include(jagFile.getPath()); return true; - } else { + }else{ return false; } }; @@ -178,20 +147,24 @@ var route; var layout = fuseState.layout; if (layout !== null) { - log.debug( - '[' + requestId + '] request for "' + path + '" will be rendered using layout "' + - layout + '" (defined in "' + mainUnit + '") and zones ' + - stringify(zones) - ); + if (log.isDebugEnabled()) { + log.debug( + '[' + requestId + '] request for "' + path + '" will be rendered using layout "' + + layout + '" (defined in "' + mainUnit + '") and zones ' + + stringify(zones) + ); + } var output = handlebars.Handlebars.compileFile(fuse.getLayoutPath(layout))({}); response.addHeader('Content-type', 'text/html'); print(output); return true; } else { - log.debug( - '[' + requestId + '] request for "' + path + '" will can\'t be rendered, since no layout is defined' + - 'in any of the units ' + stringify(zones)); + if (log.isDebugEnabled()) { + log.debug( + '[' + requestId + '] request for "' + path + '" will can\'t be rendered, since no layout is defined' + + 'in any of the units ' + stringify(zones)); + } return false; } }; @@ -207,7 +180,9 @@ var route; */ function renderLess(unit, path) { //TODO: fix - incorrect less files makes it respond the old less even if it is nocahce. - log.debug('[' + requestId + '] for unit "' + unit + '" a request received for a less file "' + path + '"'); + if (log.isDebugEnabled()) { + log.debug('[' + requestId + '] for unit "' + unit + '" a request received for a less file "' + path + '"'); + } var cacheKey = '/tmp/cached_' + unit + path.replace(/[^\w\.-]/g, '_'); fuseState.currentUnit = unit; var cachedCss = new File(cacheKey); @@ -221,7 +196,9 @@ var route; if (lessFile.isExists()) { var x = require('less-rhino-1.7.5.js'); x.compile([lessFile.getPath(), cacheKey]); - log.debug('[' + requestId + '] for unit "' + unit + '" request for "' + path + '" is cached as "' + cacheKey + '"'); + if (log.isDebugEnabled()) { + log.debug('[' + requestId + '] for unit "' + unit + '" request for "' + path + '" is cached as "' + cacheKey + '"'); + } } } diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/lib/fuse.jag b/modules/distribution/src/repository/jaggeryapps/iotserver/lib/fuse.jag index d191882d..c7731e91 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/lib/fuse.jag +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/lib/fuse.jag @@ -1,5 +1,4 @@ <% - var getPath = File.prototype.getPath; File.prototype.getPath = function() { var path = getPath.call(this); @@ -12,8 +11,7 @@ var fuseState = { zones: {}, appName: '', currentZone: [], //TODO: rename to zone Stack - currentUnit: null, - viewModelCache:{} + currentUnit: null }; var requestId = function makeId() { diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/lib/fuse.js b/modules/distribution/src/repository/jaggeryapps/iotserver/lib/fuse.js index fcc26c74..7380f57c 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/lib/fuse.js +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/lib/fuse.js @@ -15,7 +15,6 @@ var getHbsFile, getFile, toRelativePath, cleanupAncestors, for (var i = 0; i < definitions.length; i++) { var definition = definitions[i]; lookUpTable[definition.name] = i; - //log.info("initLookUp()"+definition.name+"<-"+i); } } }; @@ -46,7 +45,6 @@ var getHbsFile, getFile, toRelativePath, cleanupAncestors, }; var getAncestorModels = function (unit) { - //log.info('[' + requestId + '] getAncestorModels()'+unit); var unitModel = getUnitDefinition(unit); var ancestors = [unitModel]; var parentName; @@ -150,12 +148,11 @@ var getHbsFile, getFile, toRelativePath, cleanupAncestors, }; getUnitDefinition = function (unit) { - //log.info('[' + requestId + '] getUnitDefinition()'+unit); var definitions = getUnitDefinitions(); initLookUp(definitions); - //log.info('[' + requestId + '] lookUpTable[unit]:'+unit); var model = definitions[lookUpTable[unit]]; if (!model) { + log.warn('[' + requestId + '] unit "' + unit + '" does not exits'); throw '[' + requestId + '] unit "' + unit + '" does not exits'; } return model; @@ -208,7 +205,7 @@ var getHbsFile, getFile, toRelativePath, cleanupAncestors, var unitDir = unitDirs[i]; if (unitDir.isDirectory()) { var unitName = unitDir.getName(); - //log.info("reading: "+unitName + " basePath:'" + basePath + "'"); + //log.info("reading: "+unitName + " basePath:"+basePath); var definitionFile = new File(fuse.getUnitPath(basePath+unitName) + '/' + unitName + '.json'); if(definitionFile.isExists()) { @@ -221,7 +218,9 @@ var getHbsFile, getFile, toRelativePath, cleanupAncestors, } var path = definitionFile.getPath(); - log.debug('[' + requestId + '] reading file "' + path + '"'); + if (log.isDebugEnabled()) { + log.debug('[' + requestId + '] reading file "' + path + '"'); + } unitModel.definition = require(path); // add the information derived by parsing hbs file to the same model @@ -351,10 +350,12 @@ var getHbsFile, getFile, toRelativePath, cleanupAncestors, } while (len--) { if (toDelete[units[len]]) { - log.debug( - '[' + requestId + '] unit "' + units[len] + - '" is overridden by "' + toDelete[units[len]] + '"' - ); + if (log.isDebugEnabled()) { + log.debug( + '[' + requestId + '] unit "' + units[len] + + '" is overridden by "' + toDelete[units[len]] + '"' + ); + } units.splice(len, 1); } } @@ -384,7 +385,6 @@ var getHbsFile, getFile, toRelativePath, cleanupAncestors, * @returns {File} */ getFile = function (unitName, path, opt_suffix) { - //log.info("getFile() unitName:"+unitName+", path:"+path+", opt_suffix:"+opt_suffix); var slashPath = ((path[0] === '/') ? '' : '/') + path; var selfFileName = ''; var fileName = ''; @@ -403,21 +403,21 @@ var getHbsFile, getFile, toRelativePath, cleanupAncestors, var unitDef = getUnitDefinition(unitName); if (unitDef.path.indexOf('.hbs', unitDef.path.length - 4) !== -1) { if (opt_suffix.indexOf('.hbs', opt_suffix.length - 4) !== -1) { - //log.info("1:"+unitDef.path); return new File(unitDef.path); } else { - //log.info("2:"+unitDef.path.replace(/.hbs$/, opt_suffix)); return new File(unitDef.path.replace(/.hbs$/, opt_suffix)); } } var selfFile = new File(getUnitPath(unitName) + slashPath + selfFileName); if (selfFile.isExists()) { - log.debug( - '[' + requestId + '] for unit "' + unitName + '" file resolved : "' - + slashPath + selfFileName + '" -> "' + selfFile.getPath() + '"' - ); - //log.info("3:"+getUnitPath(unitName) + slashPath + selfFileName); + if (log.isDebugEnabled()) { + log.debug( + '[' + requestId + '] for unit "' + unitName + '" file resolved : "' + + slashPath + selfFileName + '" -> "' + selfFile.getPath() + '"' + ); + } + return selfFile; } @@ -433,19 +433,21 @@ var getHbsFile, getFile, toRelativePath, cleanupAncestors, } var file = new File(getUnitPath(ancestorName) + slashPath + fileName); if (file.isExists()) { - log.debug( - '[' + requestId + '] for unit "' + unitName + '" file resolved : "' - + slashPath + selfFileName + '" -> "' + file.getPath() + '"' - ); - //log.info("4:"+getUnitPath(ancestorName) + slashPath + fileName); + if (log.isDebugEnabled()) { + log.debug( + '[' + requestId + '] for unit "' + unitName + '" file resolved : "' + + slashPath + selfFileName + '" -> "' + file.getPath() + '"' + ); + } return file; } } - log.debug( - '[' + requestId + '] for unit "' + unitName + '" (non-excising) file resolved : "' - + slashPath + selfFileName + '" -> "' + selfFile.getPath() + '"' - ); - //log.info("5:"+getUnitPath(unitName) + slashPath + selfFileName); + if (log.isDebugEnabled()) { + log.debug( + '[' + requestId + '] for unit "' + unitName + '" (non-excising) file resolved : "' + + slashPath + selfFileName + '" -> "' + selfFile.getPath() + '"' + ); + } return selfFile; }; diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/lib/handlebars-helpers.js b/modules/distribution/src/repository/jaggeryapps/iotserver/lib/handlebars-helpers.js index 648a06f1..8c915700 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/lib/handlebars-helpers.js +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/lib/handlebars-helpers.js @@ -11,35 +11,29 @@ var getScope = function (unit,configs) { var viewModel = {}; var cbResult; if (jsFile.isExists()) { - if(fuseState.viewModelCache[jsFile.getPath()]){ - cbResult = fuseState.viewModelCache[jsFile.getPath()]; - }else{ - script = require(jsFile.getPath()); - //Eagerly make the viewModel the template configs - viewModel = templateConfigs; - //Check if the unit author has specified an onRequest - //callback - if(script.hasOwnProperty('onRequest')){ - script.app = { - url: '/' + fuseState.appName, - publicURL: '/' + fuseState.appName + '/public/' + unit, - "class": unit + '-unit' - }; - onRequestCb = script.onRequest; - cbResult = onRequestCb(templateConfigs); - log.debug("passing configs to unit "+unit+" configs: "+stringify(templateConfigs)); - fuseState.viewModelCache[jsFile.getPath()] = cbResult; + script = require(jsFile.getPath()); + //Eagerly make the viewModel the template configs + viewModel = templateConfigs; + //Check if the unit author has specified an onRequest + //callback + if(script.hasOwnProperty('onRequest')){ + script.app = { + url: '/' + fuseState.appName, + publicURL: '/' + fuseState.appName + '/public/' + unit, + "class": unit + '-unit' + }; + onRequestCb = script.onRequest; + cbResult = onRequestCb(templateConfigs); + log.debug("passing configs to unit "+unit+" configs: "+stringify(templateConfigs)); + //If the execution does not yield an object we will print + //a warning as the unit author may have forgotten to return a data object + if(cbResult===undefined){ + cbResult = {}; //Give an empty data object + log.warn('[' + requestId + '] unit "' + unit + '" has a onRequest method which does not return a value.This may lead to the ' + +'unit not been rendered correctly.'); } + viewModel = cbResult; } - - //If the execution does not yield an object we will print - //a warning as the unit author may have forgotten to return a data object - if(cbResult===undefined){ - cbResult = {}; //Give an empty data object - log.warn('[' + requestId + '] unit "' + unit + '" has a onRequest method which does not return a value.This may lead to the ' - +'unit not been rendered correctly.'); - } - viewModel = cbResult; } else{ //If there is no script then the view should get the configurations @@ -62,7 +56,7 @@ Handlebars.innerZonesFromUnit = null; Handlebars.registerHelper('defineZone', function (zoneName, zoneContent) { var result = ''; var zone = Handlebars.Utils.escapeExpression(zoneName); - fuseState.zoneStack.push(zone); + fuseState.currentZone.push(zone); var unitsToRender = fuseState.zones[zone] || []; if (Handlebars.innerZones.length > 0) { @@ -98,12 +92,12 @@ Handlebars.registerHelper('defineZone', function (zoneName, zoneContent) { return result; } - fuseState.zoneStack.pop(); + fuseState.currentZone.pop(); return new Handlebars.SafeString(result); }); Handlebars.registerHelper('zone', function (zoneName, zoneContent) { - var currentZone = fuseState.zoneStack[fuseState.zoneStack.length - 1]; + var currentZone = fuseState.currentZone[fuseState.currentZone.length - 1]; if (currentZone == null) { return 'zone_' + zoneName + ' '; } @@ -119,7 +113,7 @@ Handlebars.registerHelper('zone', function (zoneName, zoneContent) { }); Handlebars.registerHelper('layout', function (layoutName) { - var currentZone = fuseState.zoneStack[fuseState.zoneStack.length - 1]; + var currentZone = fuseState.currentZone[fuseState.currentZone.length - 1]; if (currentZone == null) { return 'layout_' + layoutName; } else { @@ -128,7 +122,7 @@ Handlebars.registerHelper('layout', function (layoutName) { }); Handlebars.registerHelper('authorized', function () { - var currentZone = fuseState.zoneStack[fuseState.zoneStack.length - 1]; + var currentZone = fuseState.currentZone[fuseState.currentZone.length - 1]; if (currentZone == null) { return ''; } else { @@ -161,11 +155,11 @@ Handlebars.registerHelper('unit', function (unitName,options) { log.error('unit does not have a main zone'); } //TODO warn when unspecified decencies are included. - fuseState.zoneStack.push('main'); + fuseState.currentZone.push('main'); var template = fuse.getFile(baseUnit, '', '.hbs'); log.debug('[' + requestId + '] including "' + baseUnit + '"'+" with configs "+stringify(templateConfigs)); var result = new Handlebars.SafeString(Handlebars.compileFile(template)(getScope(baseUnit,templateConfigs))); - fuseState.zoneStack.pop(); + fuseState.currentZone.pop(); return result; }); @@ -198,7 +192,6 @@ Handlebars.registerHelper('equal', function(lvalue, rvalue, options) { return options.fn(this); } }); - Handlebars.registerHelper('unequal', function(lvalue, rvalue, options) { if (arguments.length < 3) throw new Error("Handlebars Helper equal needs 2 parameters"); diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/lib/less-rhino-1.7.5.js b/modules/distribution/src/repository/jaggeryapps/iotserver/lib/less-rhino-1.7.5.js index 798c8563..4a191ca4 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/lib/less-rhino-1.7.5.js +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/lib/less-rhino-1.7.5.js @@ -10190,7 +10190,7 @@ var compile = function (args) { var parser = new less.Parser(options); parser.parse(input, function (e, root) { if (e) { - log.info(e); + log.error(e); writeError(e, options); quit(1); } else { diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/modules/api-wrapper-util.js b/modules/distribution/src/repository/jaggeryapps/iotserver/modules/api-wrapper-util.js new file mode 100644 index 00000000..2de3c4fa --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/modules/api-wrapper-util.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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. + */ + +var apiWrapperUtil = function () { + var module = {}; + var tokenUtil = require("/modules/util.js").util; + module.refreshToken = function () { + var tokenPair = session.get("accessTokenPair"); + tokenPair = tokenUtil.refreshToken(tokenPair); + session.put("accessTokenPair", tokenPair); + response.addCookie({'name': 'accessToken', 'value': tokenPair.accessToken}); + }; + module.setupAccessTokenPair = function (type, properties) { + var tokenPair; + var clientId = "pY0FbBUC_GI7mfHVS1FvhWAifEwa"; + var clientSecret = "Tu5Za1R3fHtGc5yH4KK8TNiLVSca"; + if (type == "password") { + //tokenPair = tokenUtil.getTokenWithPasswordGrantType(properties.username, properties.password, clientId, clientSecret); + } else if (type == "saml") { + + } + //session.put("accessTokenPair", tokenPair); + //response.addCookie({'name': 'accessToken', 'value': tokenPair.accessToken}); + }; + return module; +}(); \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/modules/constants.js b/modules/distribution/src/repository/jaggeryapps/iotserver/modules/constants.js index bd03967a..d0cc6283 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/modules/constants.js +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/modules/constants.js @@ -20,7 +20,7 @@ var WEB_APP_TITLE = "WSO2 DC - Device Cloud"; var WEB_APP_CONTEXT = "/iotserver"; var USER_SESSION_KEY = "USER"; var UNSPECIFIED = "Unspecified"; -var DEVICES_UNIT_PATH="/units/devices/"; +var DEVICES_UNIT_PATH="/units/"; var DEVICE_IDENTIFIER = "deviceIdentifier"; var DEVICE_NAME = "name"; @@ -38,7 +38,7 @@ var FEATURE_DESCRIPTION = "featureDescription"; var PLATFORM_ANDROID = "android"; var PLATFORM_IOS = "ios"; -var DEVICE_ENROLLMENT = "enrollment"; +var DEVICE_ENROLLMENT = "dateOfEnrolment"; var VENDOR_APPLE = "Apple"; var ERRORS = { diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/modules/device.js b/modules/distribution/src/repository/jaggeryapps/iotserver/modules/device.js index 8dfd6fcd..935d4071 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/modules/device.js +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/modules/device.js @@ -36,7 +36,7 @@ deviceModule = function () { var deviceManagementDAOFactory = Packages.org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; var deviceManagementService = utility.getDeviceManagementService(); - + var publicMethods = {}; var privateMethods = {}; @@ -167,7 +167,7 @@ deviceModule = function () { var data = {}; //XMLHTTPRequest's GET - log.info(removeDeviceEndpoint); + //log.info(removeDeviceEndpoint); return del(removeDeviceEndpoint, data, "text"); }; @@ -178,8 +178,8 @@ deviceModule = function () { var data = {}; //XMLHTTPRequest's POST - log.info(updateDeviceEndpoint+ "?name="+device.name); - return post(updateDeviceEndpoint+ "?name="+device.name, data, "text"); + //log.info(updateDeviceEndpoint+ "?name="+device.name); + return post(updateDeviceEndpoint + "?name=" + encodeURIComponent(device.name), data, "text"); }; /* @@ -257,8 +257,8 @@ deviceModule = function () { var deviceObject = {}; deviceObject[constants.DEVICE_IDENTIFIER] = device.getDeviceIdentifier(); deviceObject[constants.DEVICE_NAME] = privateMethods.validateAndReturn(device.getName()); - deviceObject[constants.DEVICE_OWNERSHIP] = privateMethods.validateAndReturn(device.getOwnership()); - deviceObject[constants.DEVICE_OWNER] = device.getOwner(); + deviceObject[constants.DEVICE_OWNERSHIP] = privateMethods.validateAndReturn(device.getEnrolmentInfo().getOwnership()); + deviceObject[constants.DEVICE_OWNER] = device.getEnrolmentInfo().getOwner(); deviceObject[constants.DEVICE_TYPE] = device.getType(); if (device.getType() == constants.PLATFORM_IOS) { properties[constants.DEVICE_MODEL] = properties[constants.DEVICE_PRODUCT]; @@ -266,11 +266,11 @@ deviceModule = function () { properties[constants.DEVICE_VENDOR] = constants.VENDOR_APPLE; } deviceObject[constants.DEVICE_PROPERTIES] = properties; - deviceObject[constants.DEVICE_ENROLLMENT] = device.getDateOfEnrolment(); + deviceObject[constants.DEVICE_ENROLLMENT] = device.getEnrolmentInfo().getDateOfEnrolment(); return deviceObject; } }; return publicMethods; -}(); \ No newline at end of file +}(); diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/modules/policy.js b/modules/distribution/src/repository/jaggeryapps/iotserver/modules/policy.js new file mode 100644 index 00000000..f1f45132 --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/modules/policy.js @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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. + */ + +var policyModule; +policyModule = function () { + var log = new Log("modules/policy.js"); + + var constants = require("/modules/constants.js"); + var utility = require("/modules/utility.js").utility; + + var userManagementService = utility.getUserManagementService(); + + var publicMethods = {}; + var privateMethods = {}; + + publicMethods.getPolicies = function () { + + //TODO-This method returns includes dummy policy data + + var policies = []; + var policyObj = { + "id":1, // Identifier of the policy. + "priorityId":1, // Priority of the policies. This will be used only for simple evaluation. + "profile":{}, // Profile + "policyName":"Turn off light", // Name of the policy. + "generic":true, // If true, this should be applied to all related device. + "roles":{}, // Roles which this policy should be applied. + "ownershipType":{}, // Ownership type (COPE, BYOD, CPE) + "devices":{}, // Individual devices this policy should be applied + "users":{}, // Individual users this policy should be applied + "Compliance":{}, + "policyCriterias":{}, + "startTime":283468236, // Start time to apply the policy. + "endTime":283468236, // After this time policy will not be applied + "startDate":"", // Start date to apply the policy + "endDate":"", // After this date policy will not be applied. + "tenantId":-1234, + "profileId":1 + }; + + policies.push(policyObj); + + policyObj = { + "id":2, // Identifier of the policy. + "priorityId":1, // Priority of the policies. This will be used only for simple evaluation. + "profile":{}, // Profile + "policyName":"Turn on Buzzer", // Name of the policy. + "generic":false, // If true, this should be applied to all related device. + "roles":{}, // Roles which this policy should be applied. + "ownershipType":{}, // Ownership type (COPE, BYOD, CPE) + "devices":{}, // Individual devices this policy should be applied + "users":{}, // Individual users this policy should be applied + "Compliance":{}, + "policyCriterias":{}, + "startTime":283468236, // Start time to apply the policy. + "endTime":283468236, // After this time policy will not be applied + "startDate":"", // Start date to apply the policy + "endDate":"", // After this date policy will not be applied. + "tenantId":-1234, + "profileId":2 + }; + + policies.push(policyObj); + return policies; + }; + + return publicMethods; +}(); + + diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/modules/user.js b/modules/distribution/src/repository/jaggeryapps/iotserver/modules/user.js index 4723fa79..01c9e1b5 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/modules/user.js +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/modules/user.js @@ -252,7 +252,9 @@ userModule = function () { log.error("User object was not found in the session"); throw constants.ERRORS.USER_NOT_FOUND; } + var userList = userManagementService.getUsersForTenant(carbonUser.tenantId); + var i, userObject; for (i = 0; i < userList.size(); i++) { userObject = userList.get(i); @@ -308,6 +310,34 @@ userModule = function () { return permissions; }; + /** + * Get User Roles from user store. + * If "Internal/Everyone" role is required - true param needs to be passed. + * @param enableInternalEveryone boolean value true/false to enable Internal/Everyone role + */ + publicMethods.getRoles = function (enableInternalEveryone) { + var carbonModule = require("carbon"); + var carbonServer = application.get("carbonServer"); + var carbonUser = session.get(constants.USER_SESSION_KEY); + if (!carbonUser) { + log.error("User object was not found in the session"); + throw constants.ERRORS.USER_NOT_FOUND; + } + var userManager = new carbonModule.user.UserManager(carbonServer, carbonUser.tenantId); + var allRoles = userManager.allRoles(); + var filteredRoles = []; + var i; + for (i = 0; i < allRoles.length; i++) { + if (enableInternalEveryone && allRoles[i] == "Internal/everyone") { + filteredRoles.push(allRoles[i]); + } + if (allRoles[i].indexOf("Internal/") != 0) { + filteredRoles.push(allRoles[i]); + } + } + return filteredRoles; + }; + publicMethods.logout = function (successCallback) { session.invalidate(); successCallback(); diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/modules/util.js b/modules/distribution/src/repository/jaggeryapps/iotserver/modules/util.js new file mode 100644 index 00000000..f6d413b2 --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/modules/util.js @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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. + */ + +var util = function () { + var module = {}; + var Base64 = Packages.org.apache.commons.codec.binary.Base64; + var String = Packages.java.lang.String; + var log = new Log(); + + /** + * Encode the payload in Base64 + * @param payload + * @returns {Packages.java.lang.String} + */ + function encode(payload){ + return new String(Base64.encodeBase64(new String(payload).getBytes())); + } + + /** + * Get an AccessToken pair based on username and password + * @param username + * @param password + * @param clientId + * @param clientSecret + * @param scope + * @returns {{accessToken: "", refreshToken: ""}} + */ + module.getTokenWithPasswordGrantType = function (username, password, clientId, clientSecret, scope) { + var xhr = new XMLHttpRequest(); + var tokenEndpoint = "https://localhost:9443/oauth2/token"; + var encodedClientKeys = encode(clientId + ":" + clientSecret); + xhr.open("POST", tokenEndpoint, false); + xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + xhr.setRequestHeader("Authorization", "Basic " + encodedClientKeys); + xhr.send("grant_type=password&username=" + username + "&password=" + password + "&scope=" + scope); + delete password, delete clientSecret, delete encodedClientKeys; + var tokenPair = {}; + if (xhr.status == 200) { + var data = parse(xhr.responseText); + tokenPair.refreshToken = data.refresh_token; + tokenPair.accessToken = data.access_token; + } else if (xhr.status == 403) { + throw "Error in obtaining token with Password Grant Type"; + } else { + throw "Error in obtaining token with Password Grant Type"; + } + return tokenPair; + }; + module.getTokenWithSAMLGrantType = function () { + + }; + module.refreshToken = function(tokenPair){ + var xhr = new XMLHttpRequest(); + var tokenEndpoint = "https://localhost:9443/oauth2/token"; + var encodedClientKeys = encode(clientId + ":" + clientSecret); + xhr.open("POST", tokenEndpoint, false); + xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + xhr.setRequestHeader("Authorization", "Basic " + encodedClientKeys); + xhr.send("grant_type=refresh_token&refresh_token=" + tokenPair.refreshToken + "&scope=" + scope); + delete password, delete clientSecret, delete encodedClientKeys; + var tokenPair = {}; + if (xhr.status == 200) { + var data = parse(xhr.responseText); + tokenPair.refreshToken = data.refresh_token; + tokenPair.accessToken = data.access_token; + } else if (xhr.status == 403) { + throw "Error in obtaining token with Password Grant Type"; + } else { + throw "Error in obtaining token with Password Grant Type"; + } + return tokenPair; + }; + return module; +}(); \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/modules/utility.js b/modules/distribution/src/repository/jaggeryapps/iotserver/modules/utility.js index 06f3bd4c..db2d6110 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/modules/utility.js +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/modules/utility.js @@ -41,22 +41,52 @@ utility = function () { publicMethods.insertAppPermissions = function (userModule, type) { userModule.addPermissions([{key: "device-mgt", name: "Device Management"}], "", type); - userModule.addPermissions([{key: "admin", name: "Device Management Admin"}], "device-mgt", type); - userModule.addPermissions([{key: "user", name: "Device Management User"}], "device-mgt", type); + userModule.addPermissions([{ + key: "admin", + name: "Device Management Admin" + }], "device-mgt", type); + userModule.addPermissions([{ + key: "user", + name: "Device Management User" + }], "device-mgt", type); userModule.addPermissions([{key: "devices", name: "Devices"}], "device-mgt/admin", type); - userModule.addPermissions([{key: "devices/list", name: "List Devices"}], "device-mgt/admin", type); - userModule.addPermissions([{key: "devices/operation", name: "Perform Operation"}], "device-mgt/admin", type); + userModule.addPermissions([{ + key: "devices/list", + name: "List Devices" + }], "device-mgt/admin", type); + userModule.addPermissions([{ + key: "devices/operation", + name: "Perform Operation" + }], "device-mgt/admin", type); userModule.addPermissions([{key: "users", name: "Users"}], "device-mgt/admin", type); - userModule.addPermissions([{key: "users/add", name: "Add New Users"}], "device-mgt/admin", type); - userModule.addPermissions([{key: "users/invite", name: "Invite Users"}], "device-mgt/admin", type); - userModule.addPermissions([{key: "users/list", name: "List Users"}], "device-mgt/admin", type); - userModule.addPermissions([{key: "users/remove", name: "Remove Users"}], "device-mgt/admin", type); + userModule.addPermissions([{ + key: "users/add", + name: "Add New Users" + }], "device-mgt/admin", type); + userModule.addPermissions([{ + key: "users/invite", + name: "Invite Users" + }], "device-mgt/admin", type); + userModule.addPermissions([{ + key: "users/list", + name: "List Users" + }], "device-mgt/admin", type); + userModule.addPermissions([{ + key: "users/remove", + name: "Remove Users" + }], "device-mgt/admin", type); userModule.addPermissions([{key: "devices", name: "Devices"}], "device-mgt/user", type); - userModule.addPermissions([{key: "devices/list", name: "List Devices"}], "device-mgt/user", type); - userModule.addPermissions([{key: "devices/operation", name: "Perform Operation"}], "device-mgt/user", "init"); + userModule.addPermissions([{ + key: "devices/list", + name: "List Devices" + }], "device-mgt/user", type); + userModule.addPermissions([{ + key: "devices/operation", + name: "Perform Operation" + }], "device-mgt/user", "init"); }; return publicMethods; diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/pages/dashboard.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/dashboard.hbs index 6500d10a..d11adeca 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/pages/dashboard.hbs +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/dashboard.hbs @@ -1,3 +1,4 @@ +{{authorized}} {{layout "fluid"}} {{#zone "title"}} WSO2 DC | Device Cloud diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/android.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/android.hbs index 8e4b528b..0a7b07f9 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/android.hbs +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/android.hbs @@ -4,5 +4,5 @@ {{/zone}} {{#zone "body"}} {{unit "appbar" link="store" title="STORE"}} - {{unit "devices/android"}} + {{unit "android"}} {{/zone}} \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/android_sense.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/android_sense.hbs index 0dd30cc5..b8b0b319 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/android_sense.hbs +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/android_sense.hbs @@ -4,5 +4,5 @@ {{/zone}} {{#zone "body"}} {{unit "appbar" link="store" title="STORE"}} - {{unit "devices/android_sense"}} + {{unit "android_sense"}} {{/zone}} \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/arduino.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/arduino.hbs index c957abd3..afbe5b13 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/arduino.hbs +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/arduino.hbs @@ -4,5 +4,5 @@ {{/zone}} {{#zone "body"}} {{unit "appbar" link="store" title="STORE"}} - {{unit "devices/arduino"}} + {{unit "arduino"}} {{/zone}} \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/digital_display.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/digital_display.hbs index 4b79991c..89d1b6d6 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/digital_display.hbs +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/digital_display.hbs @@ -4,5 +4,5 @@ {{/zone}} {{#zone "body"}} {{unit "appbar" link="store" title="STORE"}} - {{unit "devices/digital_display"}} + {{unit "digital_display"}} {{/zone}} \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/firealarm.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/firealarm.hbs index 89676768..8330160f 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/firealarm.hbs +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/firealarm.hbs @@ -4,5 +4,5 @@ {{/zone}} {{#zone "body"}} {{unit "appbar" link="store" title="STORE"}} - {{unit "devices/firealarm"}} + {{unit "firealarm"}} {{/zone}} \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/index.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/index.hbs index 68142bbe..ea9cd1a3 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/index.hbs +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/index.hbs @@ -4,7 +4,7 @@ Devices {{/zone}} {{#zone "body"}} - {{unit "appbar" link="device-mgt" title="Device Management"}} + {{unit "appbar" link="device-mgt" title="My Devices"}} {{unit "extended-search-box"}} {{unit "operation-mod"}}
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/raspberrypi.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/raspberrypi.hbs index 9025c456..11e7f64b 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/raspberrypi.hbs +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/raspberrypi.hbs @@ -4,5 +4,5 @@ {{/zone}} {{#zone "body"}} {{unit "appbar" link="store" title="STORE"}} - {{unit "devices/raspberrypi"}} + {{unit "raspberrypi"}} {{/zone}} \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/sensebot.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/sensebot.hbs index 4a4b58c1..a1b5049d 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/sensebot.hbs +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/sensebot.hbs @@ -4,5 +4,5 @@ {{/zone}} {{#zone "body"}} {{unit "appbar" link="store" title="STORE"}} - {{unit "devices/sensebot"}} + {{unit "sensebot"}} {{/zone}} \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/windows.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/windows.hbs index cdfa94ba..8b87456d 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/windows.hbs +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/devices/windows.hbs @@ -4,5 +4,5 @@ {{/zone}} {{#zone "body"}} {{unit "appbar" link="store" title="STORE"}} - {{unit "devices/windows"}} + {{unit "windows"}} {{/zone}} \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/pages/policies/add-policy.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/policies/add-policy.hbs new file mode 100644 index 00000000..f8a1adc7 --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/policies/add-policy.hbs @@ -0,0 +1,9 @@ +{{authorized}} +{{layout "fluid"}} +{{#zone "title"}} + WSO2 DC | Add New Policy +{{/zone}} +{{#zone "body"}} + {{unit "appbar" link="policies" title="My Policies"}} + {{unit "policy-create"}} +{{/zone}} \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/pages/policies/index.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/policies/index.hbs new file mode 100644 index 00000000..cb210ed1 --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/policies/index.hbs @@ -0,0 +1,21 @@ +{{authorized}} +{{layout "fluid"}} +{{#zone "title"}} + Policies +{{/zone}} +{{#zone "body"}} + {{unit "appbar" link="policies" title="My Policies"}} + {{unit "extended-search-box"}} +
+
+ +
+
+ +
+ {{unit "policy-listing"}} +
+ +
+
+{{/zone}} \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/test.jag b/modules/distribution/src/repository/jaggeryapps/iotserver/test.jag new file mode 100644 index 00000000..c0097b63 --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/test.jag @@ -0,0 +1,12 @@ +<% +var userModule = require("/modules/user.js").userModule; +userModule.addPermissions([{key: "device-mgt/", name: "Device Management"}], ""); +userModule.addPermissions([{key: "device-mgt/admin", name: "Device Management Admin"}], ""); +userModule.addPermissions([{key: "device-mgt/user", name: "Device Management User"}], ""); + +userModule.addPermissions([{key: "devices", name: "Device"}], "device-mgt/admin"); +userModule.addPermissions([{key: "devices", name: "Device"}], "device-mgt/user"); +userModule.addPermissions([{key: "devices/list", name: "List all Devices"}], "device-mgt/admin"); +userModule.addPermissions([{key: "devices/list", name: "List own Devices"}], "device-mgt/user"); +new Log().info(userModule.isAuthorized("/permission/device-mgt/admin/devices/list")); +%> \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/test/device-spec.js b/modules/distribution/src/repository/jaggeryapps/iotserver/test/device-spec.js new file mode 100644 index 00000000..f8ce2f3e --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/test/device-spec.js @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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. + */ + +describe('Device Module', function () { + var log = new Log(); + var mobileDB; + var cdmDB; + var deviceModule = require("/modules/device.js").deviceModule; + + function tearUp() { + mobileDB = new Database("MobileDM_DS"); + cdmDB = new Database("DM_DS"); + cdmDB.query("insert into dm_device(description, name, date_of_enrollment, date_of_last_update, " + + "ownership,status, device_type_id, device_identification, owner, tenant_id ) " + + "values ('Galaxy Tab','Admin Samsung', 1425467382, 1425467382, 'BYOD', 'ACTIVE'," + + " 1,'4892813d-0b18-4a02-b7b1-61775257488e', 'admin@wso2.com', '-1234');"); + cdmDB.query("insert into dm_device(description, name, date_of_enrollment, date_of_last_update, " + + "ownership,status, device_type_id, device_identification, owner, tenant_id ) " + + "values ('Galaxy Tab','Admin Samsung', 1425467382, 1425467382, 'BYOD', 'ACTIVE'," + + " 1,'4892813d-0b18-4a02-b7b1-61775257488F', 'mdm@wso2.com', '-1234');"); + + mobileDB.query("insert into mbl_device (mobile_device_id, push_token, imei ,imsi, os_version, " + + "device_model , vendor ,latitude ,longitude , challenge ,token, unlock_token ,serial ) " + + "values ('4892813d-0b18-4a02-b7b1-61775257488e', 'sdfsdf', 'cxv', 'vbcb', '4.1', " + + "'Galaxy Tab', 'Samsung', '234234234', '4345345234234', 'dfjsdlfk', 'wuweir234', " + + "'ksdfjlskfjwer', '234234');"); + mobileDB.query("insert into mbl_device (mobile_device_id, push_token, imei ,imsi, os_version, " + + "device_model , vendor ,latitude ,longitude , challenge ,token, unlock_token ,serial ) " + + "values ('4892813d-0b18-4a02-b7b1-61775257488F', 'sdfsdf', 'cxv', 'vbcb', '4.1', " + + "'Galaxy Tab', 'Samsung', '234234234', '4345345234234', 'dfjsdlfk', 'wuweir234', " + + "'ksdfjlskfjwer', '234234');"); + } + + function tearDown() { + deleteData(); + mobileDB.close(); + cdmDB.close(); + } + + function deleteData(){ + cdmDB.query("delete from dm_device where device_identification='4892813d-0b18-4a02-b7b1-61775257488e'"); + cdmDB.query("delete from dm_device where device_identification='4892813d-0b18-4a02-b7b1-61775257488F'"); + mobileDB.query("delete from mbl_device where mobile_device_id='4892813d-0b18-4a02-b7b1-61775257488e'"); + mobileDB.query("delete from mbl_device where mobile_device_id='4892813d-0b18-4a02-b7b1-61775257488F'"); + } + + it('List all Devices - Device Module', function () { + try { + tearUp(); + var results = deviceModule.listDevices(); + expect(results.length).not.toBe(0); + } catch (e) { + log.error(e); + throw e; + } finally { + tearDown(); + } + }); + it('List Devices for User - Device Module', function () { + try { + tearUp(); + var results = deviceModule.listDevicesForUser("mdm@wso2.com"); + expect(results.length).toBe(1); + } catch (e) { + log.error(e); + throw e; + } finally { + tearDown(); + } + }); + it('Perform operation on the device', function(){ + try { + tearUp(); + var devices = [{"id": "4892813d-0b18-4a02-b7b1-61775257488e", "type": "android"}]; + var operation = {"featureName": "DEVICE_LOCK", "type": "COMMAND", "properties": {"enabled": true}} + var results = deviceModule.performOperation(devices, operation); + expect(results.length).toBe(1); + } catch (e) { + log.error(e); + throw e; + } finally { + tearDown(); + } + }); +}); \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/test/user-spec.js b/modules/distribution/src/repository/jaggeryapps/iotserver/test/user-spec.js new file mode 100644 index 00000000..5bbf7444 --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/test/user-spec.js @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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. + */ + +describe('Device Module', function () { + var log = new Log(); + var mobileDB; + var cdmDB; + var deviceModule = require("/modules/device.js").deviceModule; + var userModule = require("/modules/user.js").userModule; + var constants = require("/modules/constants.js"); + function tearUp() { + mobileDB = new Database("MobileDM_DS"); + cdmDB = new Database("DM_DS"); + cdmDB.query("insert into dm_device(description, name, date_of_enrollment, date_of_last_update, " + + "ownership,status, device_type_id, device_identification, owner, tenant_id ) " + + "values ('Galaxy Tab','Admin Samsung', 1425467382, 1425467382, 'BYOD', 'ACTIVE'," + + " 1,'4892813d-0b18-4a02-b7b1-61775257488e', 'admin@wso2.com', '-1234');"); + cdmDB.query("insert into dm_device(description, name, date_of_enrollment, date_of_last_update, " + + "ownership,status, device_type_id, device_identification, owner, tenant_id ) " + + "values ('Galaxy Tab','Admin Samsung', 1425467382, 1425467382, 'BYOD', 'ACTIVE'," + + " 1,'4892813d-0b18-4a02-b7b1-61775257488F', 'mdm@wso2.com', '-1234');"); + + mobileDB.query("insert into mbl_device (mobile_device_id, push_token, imei ,imsi, os_version, " + + "device_model , vendor ,latitude ,longitude , challenge ,token, unlock_token ,serial ) " + + "values ('4892813d-0b18-4a02-b7b1-61775257488e', 'sdfsdf', 'cxv', 'vbcb', '4.1', " + + "'Galaxy Tab', 'Samsung', '234234234', '4345345234234', 'dfjsdlfk', 'wuweir234', " + + "'ksdfjlskfjwer', '234234');"); + mobileDB.query("insert into mbl_device (mobile_device_id, push_token, imei ,imsi, os_version, " + + "device_model , vendor ,latitude ,longitude , challenge ,token, unlock_token ,serial ) " + + "values ('4892813d-0b18-4a02-b7b1-61775257488F', 'sdfsdf', 'cxv', 'vbcb', '4.1', " + + "'Galaxy Tab', 'Samsung', '234234234', '4345345234234', 'dfjsdlfk', 'wuweir234', " + + "'ksdfjlskfjwer', '234234');"); + session.put(constants.USER_SESSION_KEY, {"username" : "admin", "domain": "carbon.super", "tenantId": "-1234"}); + } + + function tearDown() { + deleteData(); + mobileDB.close(); + cdmDB.close(); + session.put(constants.USER_SESSION_KEY, null); + } + + function deleteData(){ + cdmDB.query("delete from dm_device where device_identification='4892813d-0b18-4a02-b7b1-61775257488e'"); + cdmDB.query("delete from dm_device where device_identification='4892813d-0b18-4a02-b7b1-61775257488F'"); + mobileDB.query("delete from mbl_device where mobile_device_id='4892813d-0b18-4a02-b7b1-61775257488e'"); + mobileDB.query("delete from mbl_device where mobile_device_id='4892813d-0b18-4a02-b7b1-61775257488F'"); + } + + it('List all users', function () { + try { + tearUp(); + var results = userModule.getUsers(); + expect(results.length).not.toBe(0); + } catch (e) { + log.error(e); + throw e; + } finally { + tearDown(); + } + }); + it('Check permission for user', function () { + try { + tearUp(); + expect(userModule.isAuthorized("/permission/device-mgt/user/devices/list")).toBe(true); + } catch (e) { + log.error(e); + throw e; + } finally { + tearDown(); + } + }); +}); \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/token.jag b/modules/distribution/src/repository/jaggeryapps/iotserver/token.jag new file mode 100644 index 00000000..77778307 --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/token.jag @@ -0,0 +1,4 @@ +<% +var apiWrapperUtil = require("/modules/api-wrapper-util.js").apiWrapperUtil; +apiWrapperUtil.refreshToken(); +%> \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/analytics/analytics.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/units/analytics/analytics.hbs index 9575d03e..27abf139 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/units/analytics/analytics.hbs +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/analytics/analytics.hbs @@ -48,6 +48,8 @@
+
+
@@ -70,4 +72,5 @@ + {{/zone}} \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/analytics/public/js/graph_util.js b/modules/distribution/src/repository/jaggeryapps/iotserver/units/analytics/public/js/graph_util.js index c8dbd110..2a2f76ba 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/units/analytics/public/js/graph_util.js +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/analytics/public/js/graph_util.js @@ -1,6 +1,10 @@ var fromDate; var toDate; +var currentDay = new Date(); +var startDate = new Date(currentDay.getTime() - (60 * 60 * 24 * 100)); +var endDate = new Date(currentDay.getTime()); + // create a custom bar renderer that has no gaps Rickshaw.Graph.Renderer.BarNoGap = Rickshaw.Class.create(Rickshaw.Graph.Renderer.Bar, { name: 'bar_no_gap', @@ -11,10 +15,11 @@ Rickshaw.Graph.Renderer.BarNoGap = Rickshaw.Class.create(Rickshaw.Graph.Renderer } }); - -var currentDay = new Date(); -var startDate = new Date(currentDay.getTime() - (60 * 60 * 24 * 100)); -var endDate = new Date(currentDay.getTime()); +function initDate(){ + currentDay = new Date(); + startDate = new Date(currentDay.getTime() - (60 * 60 * 24 * 100)); + endDate = new Date(currentDay.getTime()); +} var configObject = { startOfWeek: 'monday', @@ -38,6 +43,7 @@ var configObject = { var DateRange = convertDate(startDate) + " " + configObject.separator + " " + convertDate(endDate); $(document).ready(function () { + initDate(); $('#date-range').dateRangePicker(configObject) .bind('datepicker-apply', function (event, dateRange) { $(this).addClass('active'); @@ -61,21 +67,25 @@ $(document).ready(function () { //day picker $('#today-btn').on('click', function () { + initDate(); getDateTime(currentDay.getTime() - 86400000, currentDay.getTime()); }); //hour picker $('#hour-btn').on('click', function () { + initDate(); getDateTime(currentDay.getTime() - 3600000, currentDay.getTime()); -}) +}); //week picker $('#week-btn').on('click', function () { + initDate(); getDateTime(currentDay.getTime() - 604800000, currentDay.getTime()); -}) +}); //month picker $('#month-btn').on('click', function () { + initDate(); getDateTime(currentDay.getTime() - (604800000 * 4), currentDay.getTime()); }); @@ -148,69 +158,77 @@ function updateGraphs(stats) { console.log(stats); var temperatureData = stats['temperatureData']; - if (typeof temperatureData != 'undefined'){ + if (typeof temperatureData != 'undefined') { $('#div-temperatureData').html("").html("

Temperature



"); updateTemperatureGraph(convertStatsToGraphData(temperatureData)); - }else{ + } else { $('#div-temperatureData').html(""); } var lightData = stats['lightData']; - if (typeof lightData != 'undefined'){ + if (typeof lightData != 'undefined') { $('#div-lightData').html("").html("

Light



"); updateLightGraph(convertStatsToGraphData(lightData)); - }else{ + } else { $('#div-lightData').html(""); } var motionData = stats['motionData']; - if (typeof motionData != 'undefined'){ + if (typeof motionData != 'undefined') { $('#div-motionData').html("").html("

Motion



"); updateMotionGraph(convertStatsToGraphData(motionData)); - }else{ + } else { $('#div-motionData').html(""); } var sonarData = stats['sonarData']; - if (typeof sonarData != 'undefined'){ + if (typeof sonarData != 'undefined') { $('#div-sonarData').html("").html("

Sonar



"); updateSonarGraph(convertStatsToGraphData(sonarData)); - }else{ + } else { $('#div-sonarData').html(""); } var fanData = stats['fanData']; - if (typeof fanData != 'undefined'){ + if (typeof fanData != 'undefined') { $('#div-fanData').html("").html("

Fan Status



"); updateFanGraph(convertStateStatsToGraphData(fanData)); - }else{ + } else { $('#div-fanData').html(""); } var bulbData = stats['bulbData']; - if (typeof bulbData != 'undefined'){ + if (typeof bulbData != 'undefined') { $('#div-bulbData').html("").html("

Bulb Status



"); updateBulbGraph(convertStateStatsToGraphData(bulbData)); - }else{ + } else { $('#div-bulbData').html(""); } var cpuData = stats['cpuData']; - if (typeof cpuData != 'undefined'){ + if (typeof cpuData != 'undefined') { $('#div-CPUData').html("").html("

CPU Load



"); updateCPUGraph(convertStateStatsToGraphData(cpuData)); - }else{ + } else { $('#div-CPUData').html(""); } var ramData = stats['ramData']; - if (typeof ramData != 'undefined'){ + if (typeof ramData != 'undefined') { $('#div-RAMData').html("").html("

RAM Usage



"); updateRAMGraph(convertStateStatsToGraphData(ramData)); - }else{ + } else { $('#div-RAMData').html(""); } + var cpuTemperatureData = stats['cpuTemperatureData']; + if (typeof cpuTemperatureData != 'undefined') { + $('#div-cpuTemperatureData').html("").html("

CPU Temperature



"); + updateCPUTemperatureGraph(convertStatsToGraphData(cpuTemperatureData)); + } else { + $('#div-cpuTemperatureData').html(""); + } + scaleGraphs(); } @@ -219,8 +237,18 @@ function scaleGraphs() { if (sliders.length == 0) { return; } + var graphWidth = 0; + for (var i = 1; i < 10; i++){ + if ($('#canvas-wrapper' + i).length){ + graphWidth = $('#canvas-wrapper' + i).width() - 50; + break; + } + } + + if (graphWidth <= 0){ + return; + } - var graphWidth = $('#canvas-wrapper1').width() - 50; //Scale graphs var sliderX = graphWidth * 60 * 60 / (toDate - fromDate); if (sliderX < graphWidth) { @@ -283,9 +311,9 @@ function convertStateStatsToGraphData(stats) { function convertDate(date) { var month = date.getMonth() + 1; var day = date.getDate(); - var hour=date.getHours(); - var minute=date.getMinutes(); + var hour = date.getHours(); + var minute = date.getMinutes(); return date.getFullYear() + '-' + (('' + month).length < 2 ? '0' : '') - + month + '-' + (('' + day).length < 2 ? '0' : '') + day +" "+ (('' + hour).length < 2 ? '0' : '') - + hour +":"+(('' + minute).length < 2 ? '0' : '')+ minute; + + month + '-' + (('' + day).length < 2 ? '0' : '') + day + " " + (('' + hour).length < 2 ? '0' : '') + + hour + ":" + (('' + minute).length < 2 ? '0' : '') + minute; } \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/analytics/public/js/graphs/cpu_temperature_graph.js b/modules/distribution/src/repository/jaggeryapps/iotserver/units/analytics/public/js/graphs/cpu_temperature_graph.js new file mode 100644 index 00000000..cc381c96 --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/analytics/public/js/graphs/cpu_temperature_graph.js @@ -0,0 +1,70 @@ +function updateCPUTemperatureGraph(temperatureData) { + console.log("cpuTemperatureData"); + renderCPUTemperatureChart(temperatureData); +} + +function renderCPUTemperatureChart(chartDataRaw) { + var chartWrapperElmId = "#canvas-wrapper9"; + var graphWidth = $(chartWrapperElmId).width() - 50; + if (chartDataRaw.length == 0) { + $(chartWrapperElmId).html("No data available..."); + return; + } + + var chartData = []; + for (var i = 0; i < chartDataRaw.length; i++) { + chartData.push({x: parseInt(chartDataRaw[i].x), y: parseInt(chartDataRaw[i].y)}); + } + + //var i = parseInt(fromDate); + //while (i < parseInt(toDate)){ + // var rnd = Math.random() * (30 - 20) + 20; + // chartData.push({x:i * 1000, y:rnd}); + // i += 60 * 5; + //} + + var chartDiv = "chart9"; + var sliderDiv = "slider9"; + var x_axis = "x_axis9"; + var y_axis = "y_axis9"; + $(chartWrapperElmId).html("").html('
'); + + var graph = new Rickshaw.Graph({ + element: document.getElementById(chartDiv), + width: graphWidth, + height: 400, + strokeWidth: 1, + renderer: 'line', + xScale: d3.time.scale(), + padding: {top: 0.2, left: 0.02, right: 0.02, bottom: 0}, + series: [ + {color: '#FF4000', data: chartData} + ] + }); + + graph.render(); + + var xAxis = new Rickshaw.Graph.Axis.X({ + graph: graph, + orientation: 'bottom', + element: document.getElementById(x_axis), + tickFormat: graph.x.tickFormat() + }); + + xAxis.render(); + + var yAxis = new Rickshaw.Graph.Axis.Y({ + graph: graph, + orientation: 'left', + element: document.getElementById(y_axis), + width: 40, + height: 410 + }); + + yAxis.render(); + + var slider = new Rickshaw.Graph.RangeSlider.Preview({ + graph: graph, + element: document.getElementById(sliderDiv) + }); +} \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android/android.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/units/android/android.hbs similarity index 100% rename from modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android/android.hbs rename to modules/distribution/src/repository/jaggeryapps/iotserver/units/android/android.hbs diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/android/android.js b/modules/distribution/src/repository/jaggeryapps/iotserver/units/android/android.js new file mode 100644 index 00000000..dae1a137 --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/android/android.js @@ -0,0 +1,4 @@ +function onRequest(context){ + context.sketchPath = "api/device/sketch/download"; + return context; +} diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android/android.json b/modules/distribution/src/repository/jaggeryapps/iotserver/units/android/android.json similarity index 100% rename from modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android/android.json rename to modules/distribution/src/repository/jaggeryapps/iotserver/units/android/android.json diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android/public/images/android-thumb.png b/modules/distribution/src/repository/jaggeryapps/iotserver/units/android/public/images/android-thumb.png similarity index 100% rename from modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android/public/images/android-thumb.png rename to modules/distribution/src/repository/jaggeryapps/iotserver/units/android/public/images/android-thumb.png diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android/public/images/android.png b/modules/distribution/src/repository/jaggeryapps/iotserver/units/android/public/images/android.png similarity index 100% rename from modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android/public/images/android.png rename to modules/distribution/src/repository/jaggeryapps/iotserver/units/android/public/images/android.png diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android/public/store.json b/modules/distribution/src/repository/jaggeryapps/iotserver/units/android/public/store.json similarity index 100% rename from modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android/public/store.json rename to modules/distribution/src/repository/jaggeryapps/iotserver/units/android/public/store.json diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android_sense/android_sense.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/units/android_sense/android_sense.hbs similarity index 100% rename from modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android_sense/android_sense.hbs rename to modules/distribution/src/repository/jaggeryapps/iotserver/units/android_sense/android_sense.hbs diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/android_sense/android_sense.js b/modules/distribution/src/repository/jaggeryapps/iotserver/units/android_sense/android_sense.js new file mode 100644 index 00000000..dae1a137 --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/android_sense/android_sense.js @@ -0,0 +1,4 @@ +function onRequest(context){ + context.sketchPath = "api/device/sketch/download"; + return context; +} diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android_sense/android_sense.json b/modules/distribution/src/repository/jaggeryapps/iotserver/units/android_sense/android_sense.json similarity index 100% rename from modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android_sense/android_sense.json rename to modules/distribution/src/repository/jaggeryapps/iotserver/units/android_sense/android_sense.json diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android_sense/public/images/android_sense-thumb.png b/modules/distribution/src/repository/jaggeryapps/iotserver/units/android_sense/public/images/android_sense-thumb.png similarity index 100% rename from modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android_sense/public/images/android_sense-thumb.png rename to modules/distribution/src/repository/jaggeryapps/iotserver/units/android_sense/public/images/android_sense-thumb.png diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android_sense/public/images/android_sense.png b/modules/distribution/src/repository/jaggeryapps/iotserver/units/android_sense/public/images/android_sense.png similarity index 100% rename from modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android_sense/public/images/android_sense.png rename to modules/distribution/src/repository/jaggeryapps/iotserver/units/android_sense/public/images/android_sense.png diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android_sense/public/store.json b/modules/distribution/src/repository/jaggeryapps/iotserver/units/android_sense/public/store.json similarity index 100% rename from modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/android_sense/public/store.json rename to modules/distribution/src/repository/jaggeryapps/iotserver/units/android_sense/public/store.json diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/appbar/appbar.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/units/appbar/appbar.hbs index e82f3989..20489738 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/units/appbar/appbar.hbs +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/appbar/appbar.hbs @@ -41,11 +41,11 @@ diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/appbar/appbar.js b/modules/distribution/src/repository/jaggeryapps/iotserver/units/appbar/appbar.js index 7d0416b2..381b757a 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/units/appbar/appbar.js +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/appbar/appbar.js @@ -1,6 +1,6 @@ function onRequest(context) { var constants = require("/modules/constants.js"); - var user = session.get(constants.USER_SESSION_KEY); + var carbonUser = session.get(constants.USER_SESSION_KEY); var links = { "users": [], @@ -18,7 +18,7 @@ function onRequest(context) { }; var deviceMgtLink = { - title: "Go back to Device Management", + title: "Go back to My Devices", icon: "fw-left-arrow", url: "/iotserver/devices" }; @@ -38,9 +38,12 @@ function onRequest(context) { links.analytics.push(deviceMgtLink); links['device-mgt'].push(dashboardLink); - if (user) { + if (!carbonUser) { + //user is not logged in + }else{ var userModule = require("/modules/user.js").userModule; var permissions = userModule.getUIPermissions(); + context.permissions = permissions; //if (permissions.ADD_USER) { diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/arduino/arduino.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/units/arduino/arduino.hbs similarity index 100% rename from modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/arduino/arduino.hbs rename to modules/distribution/src/repository/jaggeryapps/iotserver/units/arduino/arduino.hbs diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/arduino/arduino.js b/modules/distribution/src/repository/jaggeryapps/iotserver/units/arduino/arduino.js new file mode 100644 index 00000000..dae1a137 --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/arduino/arduino.js @@ -0,0 +1,4 @@ +function onRequest(context){ + context.sketchPath = "api/device/sketch/download"; + return context; +} diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/arduino/arduino.json b/modules/distribution/src/repository/jaggeryapps/iotserver/units/arduino/arduino.json similarity index 100% rename from modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/arduino/arduino.json rename to modules/distribution/src/repository/jaggeryapps/iotserver/units/arduino/arduino.json diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/arduino/public/images/arduino-thumb.png b/modules/distribution/src/repository/jaggeryapps/iotserver/units/arduino/public/images/arduino-thumb.png similarity index 100% rename from modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/arduino/public/images/arduino-thumb.png rename to modules/distribution/src/repository/jaggeryapps/iotserver/units/arduino/public/images/arduino-thumb.png diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/arduino/public/images/arduino.png b/modules/distribution/src/repository/jaggeryapps/iotserver/units/arduino/public/images/arduino.png similarity index 100% rename from modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/arduino/public/images/arduino.png rename to modules/distribution/src/repository/jaggeryapps/iotserver/units/arduino/public/images/arduino.png diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/arduino/public/store.json b/modules/distribution/src/repository/jaggeryapps/iotserver/units/arduino/public/store.json similarity index 100% rename from modules/distribution/src/repository/jaggeryapps/iotserver/units/devices/arduino/public/store.json rename to modules/distribution/src/repository/jaggeryapps/iotserver/units/arduino/public/store.json diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-detail/public/js/device-detail.js b/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-detail/public/js/device-detail.js index 18462e9d..c453c889 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-detail/public/js/device-detail.js +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-detail/public/js/device-detail.js @@ -24,7 +24,46 @@ function formatDates(){ } (function () { + var deviceId = $(".device-id"); + var deviceIdentifier = deviceId.data("deviceid"); + var deviceType = deviceId.data("type"); + var payload = [deviceIdentifier]; + if (deviceType == "ios") { + var serviceUrl = "/ios/operation/deviceinfo"; + } else if (deviceType == "android") { + var serviceUrl = "/mdm-android-agent/operation/device-info"; + } + invokerUtil.post(serviceUrl, payload, + function(message){ + console.log(message); + }, function (message) { + console.log(message); + }); $(document).ready(function(){ + loadOperationBar(deviceType); + loadMap(); formatDates(); }); + function loadMap(){ + var map; + function initialize() { + var mapOptions = { + zoom: 18 + }; + var lat = 6.9098591; + var long = 79.8523753; + map = new google.maps.Map(document.getElementById('device-location'), + mapOptions); + + var pos = new google.maps.LatLng(lat, + long); + var marker = new google.maps.Marker({ + position: pos, + map: map + }); + + map.setCenter(pos); + } + google.maps.event.addDomListener(window, 'load', initialize); + } }()); diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-listing/device-listing.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-listing/device-listing.hbs index 8dddd607..17444875 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-listing/device-listing.hbs +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-listing/device-listing.hbs @@ -93,7 +93,7 @@

Device was successfully updated.

@@ -165,4 +165,4 @@ {{#zone "bottomJs"}} -{{/zone}} \ No newline at end of file +{{/zone}} diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-listing/public/js/device-listing.js b/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-listing/public/js/device-listing.js index 097882cd..0116b272 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-listing/public/js/device-listing.js +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-listing/public/js/device-listing.js @@ -168,7 +168,7 @@ function loadDevices(searchType, searchParam) { addDeviceSelectedClass(this); }); attachEvents(); - formatDates(); + //formatDates(); } }; invokerUtil.get(serviceURL, @@ -253,24 +253,25 @@ function attachEvents() { $("a#remove-device-yes-link").click(function () { invokerUtil.get( removeDeviceAPI, - function (data) { - if (data == 200) { - $("#" + username).addClass("hide"); + function (data,txtStatus,jqxhr) { + var status = jqxhr.status; + if (status == 200) { $(modalPopupContent).html($('#remove-device-200-content').html()); - $("a#remove-device-200-link").click(function () { + $('div[data-deviceid="' + deviceId + '"]').remove(); + $("a#remove-device-200-link").click(function () { hidePopup(); }); - } else if (data == 400) { + } else if (status == 400) { $(modalPopupContent).html($('#remove-device-400-content').html()); $("a#remove-device-400-link").click(function () { hidePopup(); }); - } else if (data == 403) { + } else if (status == 403) { $(modalPopupContent).html($('#remove-device-403-content').html()); $("a#remove-device-403-link").click(function () { hidePopup(); }); - } else if (data == 409) { + } else if (status == 409) { $(modalPopupContent).html($('#remove-device-409-content').html()); $("a#remove-device-409-link").click(function () { hidePopup(); @@ -308,28 +309,30 @@ function attachEvents() { showPopup(); $("a#edit-device-yes-link").click(function () { - var device={"device":{"name" : $('#edit-device-name').val()}}; + var newDeviceName = $('#edit-device-name').val(); + var device={"device":{"name" : newDeviceName}}; invokerUtil.post( editDeviceAPI, device, - function (data) { - if (data == 200) { - $("#" + username).addClass("hide"); + function (data,txtStatus,jqxhr) { + var status = jqxhr.status; + if (status == 200) { $(modalPopupContent).html($('#edit-device-200-content').html()); + $("div[data-deviceid='"+deviceId+"'] .ast-name").html(newDeviceName); $("a#edit-device-200-link").click(function () { hidePopup(); }); - } else if (data == 400) { + } else if (status == 400) { $(modalPopupContent).html($('#edit-device-400-content').html()); $("a#edit-device-400-link").click(function () { hidePopup(); }); - } else if (data == 403) { + } else if (status == 403) { $(modalPopupContent).html($('#edit-device-403-content').html()); $("a#edit-device-403-link").click(function () { hidePopup(); }); - } else if (data == 409) { + } else if (status == 409) { $(modalPopupContent).html($('#edit-device-409-content').html()); $("a#edit-device-409-link").click(function () { hidePopup(); diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-listing/public/templates/device-listing.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-listing/public/templates/device-listing.hbs index 767aab17..0ffc884e 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-listing/public/templates/device-listing.hbs +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-listing/public/templates/device-listing.hbs @@ -1,6 +1,6 @@ {{#each devices}} {{deviceMap this}} -
+