moving files from extension into namespaced ang file
authorNikki Murray <nikki.liz.murray@gmail.com>
Tue, 13 Oct 2015 14:43:41 +0000 (10:43 -0400)
committerNikki Murray <nikki.liz.murray@gmail.com>
Tue, 13 Oct 2015 19:23:11 +0000 (15:23 -0400)
ang/crmStatusPage.css [new file with mode: 0644]
ang/crmStatusPage.js [new file with mode: 0644]
ang/crmStatusPage/SnoozeOptions.html [new file with mode: 0644]
ang/crmStatusPage/StatusPage.html [new file with mode: 0644]
ang/crmStatusPage/StatusPageServices.js [new file with mode: 0644]
ang/crmStatusPage/StatuspageCtrl.js [new file with mode: 0644]
ang/crmStatusPage/crmSnoozeOption.js [new file with mode: 0644]

diff --git a/ang/crmStatusPage.css b/ang/crmStatusPage.css
new file mode 100644 (file)
index 0000000..604037e
--- /dev/null
@@ -0,0 +1,70 @@
+/* Add any CSS rules for Angular module "statuspage" */
+
+/* Error Severity */
+#crm-status-list .crm-severity-emergency,
+#crm-status-list .crm-severity-alert,
+#crm-status-list .crm-severity-critical,
+#crm-status-list .crm-severity-error{
+  background-color: #E43D2B;
+  color: white;
+}
+
+#crm-status-list .crm-severity-emergency:hover,
+#crm-status-list .crm-severity-alert:hover,
+#crm-status-list .crm-severity-critical:hover,
+#crm-status-list .crm-severity-error:hover {
+  background-color: #DD0000;
+  color: white;
+}
+
+/* Warning Severity */
+#crm-status-list .crm-severity-warning
+{
+  background-color: #EDA737;
+  color: white;
+}
+
+#crm-status-list .crm-severity-warning:hover
+{
+  background-color: #F09E1A;
+  color: white;
+}
+
+
+/* Not Okay - Not Warning */
+#crm-status-list .crm-severity-notice
+{
+  background-color: #4A88DF;
+  color: white;
+}
+
+#crm-status-list .crm-severity-notice :hover
+{
+  background-color: #41477E;
+  color: white;
+}
+
+/* All OK Severity */
+#crm-status-list .crm-severity-info,
+#crm-status-list .crm-severity-debug {
+  background-color: #00994D;
+  color: white;
+}
+
+
+#crm-status-list .crm-severity-info:hover,
+#crm-status-list .crm-severity-debug:hover {
+  background-color: #006633;
+  color: white;
+}
+
+/* over-riding divs for snooze-options so that inline-block looks better */
+
+.crm-container .status-snooze-options .crm-section .content,
+.crm-container .status-snooze-options .crm-section .label {
+  margin-left: inherit;
+  text-align: inherit;
+  float: inherit;
+  width: inherit;
+  display: inline-block;
+}
diff --git a/ang/crmStatusPage.js b/ang/crmStatusPage.js
new file mode 100644 (file)
index 0000000..eae1077
--- /dev/null
@@ -0,0 +1,46 @@
+(function(angular, $, _) {
+  // Declare a list of dependencies.
+  angular.module('statuspage', [
+    'crmUi', 'crmUtil', 'ngRoute'
+  ]);
+
+  // router
+
+  angular.module('statuspage').config( function($routeProvider) {
+    $routeProvider.when('/status', {
+      controller: 'statuspageStatusPage',
+      templateUrl: '~/statuspage/StatusPage.html',
+
+      resolve: {
+        statuses: function(statuspageGetStatuses) {
+          return statuspageGetStatuses({is_visible: 1});
+        },
+        statusModel: function(statuspageStatusModel) {
+          return statuspageStatusModel();
+        },
+        preferences: function(statuspageGetPreferences){
+          return statuspageGetPreferences();
+        }
+      }
+    });
+
+    $routeProvider.when('/status/hushed', {
+      controller: 'statuspageStatusPage',
+      templateUrl: '~/statuspage/StatusPage.html',
+
+      resolve: {
+        statuses: function(statuspageGetStatuses) {
+          return statuspageGetStatuses({is_visible: 0});
+        },
+        statusModel: function(statuspageStatusModel) {
+          return statuspageStatusModel();
+        },
+        preferences: function(statuspageGetPreferences){
+          return statuspageGetPreferences();
+        }
+      }
+    });
+
+  }
+);
+})(angular, CRM.$, CRM._);
diff --git a/ang/crmStatusPage/SnoozeOptions.html b/ang/crmStatusPage/SnoozeOptions.html
new file mode 100644 (file)
index 0000000..7a89001
--- /dev/null
@@ -0,0 +1,7 @@
+<span ng-form="snoozeOptions" crm-ui-id-scope style="display: inline">
+    <span crm-ui-field="{name: 'snoozeOptions.until', title: ts('Snooze until')}" style="display: inline" >
+        <input name="until" crm-ui-datepicker ng-model="status.snoozeOptions.until" style="display: inline" />
+        <a crm-icon="fa-floppy-o" ng-click="snooze(status)" class="crm-hover-button" title="{{ts('Save Preference')}}"></a>
+      <span>
+</span>
+ <!-- snooze options page, creates a box for picking a date you would like to snooze a status alert until -->
diff --git a/ang/crmStatusPage/StatusPage.html b/ang/crmStatusPage/StatusPage.html
new file mode 100644 (file)
index 0000000..327cc62
--- /dev/null
@@ -0,0 +1,37 @@
+<div class="crm-container">
+  <div crm-ui-debug="statuses"></div>
+  <div crm-ui-debug="preferences"></div>
+
+  <form name="myForm" crm-ui-id-scope>
+
+    <div class="help">
+      <p>{{ts('Help messages will be displayed here')}}</p>
+    </div>
+
+    <div>
+      <h1>Status Page</h1><br />
+      <button ng-if="(path === '/status/hushed')" ng-click="navigator.redirect('#/status')">Return home</button>
+      <button ng-if="(path === '/status')" ng-click="navigator.redirect('#/status/hushed')">Show snoozed and hushed</button>
+    </div>
+    <div id="crm-status-list" ng-repeat="status in statuses.values track by status.name" >
+      <h3 class="crm-severity-{{status.severity}}">{{status.title}}
+        <span class="status-snooze-options" ng-show="status.snoozeOptions.show" style="display: inline-block">
+          <div crm-snooze-options style="display: inline"></div>
+        </span>
+          <a  ng-if="(path === '/status')"  ng-click="showSnoozeOptions(status)" ng-show="!status.snoozeOptions.show" class="crm-hover-button" crm-icon="fa-clock-o" title="{{ts('Snooze')}}"></a>
+          <a ng-click="showSnoozeOptions(status)" ng-show="status.snoozeOptions.show" class="crm-hover-button" crm-icon="fa-times" style="display: inline" title="{{ts('Close')}}"></a>
+          <a ng-if="(path === '/status')" ng-click="hush(status.name, status.severity)" class="crm-hover-button" crm-icon="fa-bell-slash-o" title="{{ts('Hush')}}"></a>
+          <a ng-if="(path === '/status/hushed')" ng-click="unhush(status.name)" class="crm-hover-button" crm-icon="fa-bell-o" title="{{ts('Unhush And Unsnooze')}}"></a>
+      </h3>
+      <h4>
+        <div class="crm-block">
+          <div class="crm-group">
+            <div class="crm-status-message-body" ng-bind-html="status.message | trusted"></div>
+          </div>
+        </div>
+      </h4><br/>
+    </div>
+
+  </form>
+
+</div>
diff --git a/ang/crmStatusPage/StatusPageServices.js b/ang/crmStatusPage/StatusPageServices.js
new file mode 100644 (file)
index 0000000..fe86fc8
--- /dev/null
@@ -0,0 +1,64 @@
+(function(angular, $, _) {
+
+/**
+ * get status messages
+ * build snooze options object reconciled with preferences
+ *
+ */
+  angular.module('statuspage').service('statuspageStatusModel', function(crmApi, statuspageGetStatuses, statuspageGetPreferences){
+    return function() {
+      var statusModel = {
+        hushed: false,
+        getStatuses: statuspageGetStatuses,
+        getPreferences: statuspageGetPreferences,
+      };
+      statusModel.statuses = statusModel
+        .getStatuses(statusModel.hushed)
+          .then(function(result){
+            result.preferences = statuspageGetPreferences();
+            return result;
+          });
+    };
+  });
+
+  angular.module('statuspage').service('statuspageGetStatuses', function(crmApi, statuspageSeverityList) {
+    return function(apiFilter) {
+      return crmApi('System', 'check', apiFilter)
+        .catch(function(obj){console.log(obj)})
+        .then(function(apiResults){
+          _.each(apiResults.values, function(status){
+            status.severity_id = status.severity;
+            status.severity = statuspageSeverityList[status.severity];
+            status.displayTitle = status.name+' - '+status.title +' - '+status.severity.toUpperCase();
+            status.snoozeOptions = {
+              show: false,
+              severity: status.severity
+            };
+          });
+          return apiResults;
+        })
+      }
+  });
+
+  angular.module('statuspage').service('statuspageGetPreferences', function(crmApi) {
+    return function() {
+      return crmApi('StatusPreference', 'get')
+        .then(function(apiResults) {
+          _.each(apiResults.values, function(pref){
+            pref.snoozeOptions = {
+              severity: pref.ignore_severity
+            };
+          });
+          return apiResults;
+        });
+    };
+  });
+
+
+  angular.module('statuspage').filter('trusted', function($sce){ return $sce.trustAsHtml; });
+
+  angular.module('statuspage').service('statuspageSeverityList', function() {
+    return ['debug', 'info', 'notice', 'warning', 'error', 'critical', 'alert', 'emergency'];
+  });
+
+})(angular, CRM.$, CRM._);
diff --git a/ang/crmStatusPage/StatuspageCtrl.js b/ang/crmStatusPage/StatuspageCtrl.js
new file mode 100644 (file)
index 0000000..79c30b3
--- /dev/null
@@ -0,0 +1,77 @@
+(function(angular, $, _) {
+
+  // controller
+
+  angular.module('statuspage').controller('statuspageStatusPage',
+    function($scope, $location, crmApi, crmStatus, crmUiHelp, statuses, crmNavigator, preferences) {
+    // The ts() and hs() functions help load strings for this module.
+    var ts = $scope.ts = CRM.ts('statuspage');
+    var hs = $scope.hs = crmUiHelp({file: 'CRM/statuspage/StatusPage'}); // See: templates/CRM/statuspage/StatusPage.hlp
+
+    $scope.path = $location.path();
+    $scope.navigator = crmNavigator;
+    $scope.statuses = statuses;
+    console.log(preferences)
+    $scope.preferences = preferences;
+
+    // will "hush" a status - gets the severity level of the status that is being hushed, and hushes all alerts for that check at and below the level of the current check
+    $scope.hush = function(name, severity) {
+      return  crmStatus(
+        { start: ts('Saving Status Preference...')      , success: ts('Preference Saved') },
+        crmApi('StatusPreference', 'create', {
+          "sequential": 1,
+          "name": name,
+          "ignore_severity": severity,
+          "hush_until":  ""
+        })
+        .then(function(){rmStatus($scope, name);})
+      );
+    };
+
+    // will reset ignore_severity to 0 to unhush the status alert.
+    $scope.unhush = function(name, severity) {
+      return  crmStatus(
+        { start: ts('Saving Status Preference...')      , success: ts('Preference Saved') },
+        crmApi('StatusPreference', 'create', {
+          "sequential": 1,
+          "name": name,
+          "ignore_severity": 0,
+          "hush_until": ""
+        })
+        .then(function(){rmStatus($scope, name);})
+      );
+    };
+
+    // will 'snooze' a status - will not show alerts at that level for that check + alerts below that level for that check until the specified date
+    $scope.snooze = function(status) {
+      $scope.showSnoozeOptions(status);
+      return crmStatus(
+        { status: ts('Saving Status Preference...')   , success: ts('Preference Saved') },
+          crmApi('StatusPreference', 'create', {
+            "sequential": 1,
+            "name": status.name,
+            "ignore_severity": status.snoozeOptions.severity,
+            "hush_until": status.snoozeOptions.until
+          })        .then(function(){rmStatus($scope, status.name);})
+      );
+    };
+    $scope.showSnoozeOptions = function(status) {
+      status.snoozeOptions.show = !status.snoozeOptions.show;
+    };
+  });
+
+
+  /**
+   * remove a status after it has been hushed/snoozed
+   * @param {type} $scope
+   * @param {type} statusName
+   * @returns void
+   */
+   function rmStatus($scope, statusName) {
+    $scope.statuses.values =  _.reject($scope.statuses.values,
+      function(status) {
+        return status.name === statusName;
+    });
+  }
+
+})(angular, CRM.$, CRM._);
diff --git a/ang/crmStatusPage/crmSnoozeOption.js b/ang/crmStatusPage/crmSnoozeOption.js
new file mode 100644 (file)
index 0000000..b11cfd8
--- /dev/null
@@ -0,0 +1,13 @@
+// creates a directive for the snooze options page
+
+(function(angular, $, _) {
+  angular.module('statuapage').directive('crmSnoozeOptions', function(statuspageSeverityList) {
+    return {
+      templateUrl: '~/statuspage/SnoozeOptions.html',
+      transclude: true,
+      link: function(scope, element, attr) {
+        scope.severityList = statuspageSeverityList;
+      }
+    };
+  });
+})(angular, CRM.$, CRM._);