Created
January 17, 2017 21:12
-
-
Save mozrat/f11f6902a35a6a88d1edb58cdc731551 to your computer and use it in GitHub Desktop.
I'm affected too button
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function ($scope, spUtil, snRecordWatcher, $rootScope) { | |
var c = this; | |
$scope.standalone = $scope.options.standalone == 'true' || $scope.options.standalone == true; | |
var q = "cmdb_ci.sys_class_name=cmdb_ci_service"; | |
if ($scope.data.outageIDs != "") | |
q += "^NQ" + $scope.data.outageIDs; | |
snRecordWatcher.initList("cmdb_ci_outage", q); | |
function get() { | |
$rootScope.$broadcast("sp.outage.updated"); | |
spUtil.update($scope); | |
} | |
$scope.$on('record.updated', get); | |
c.createIncident = function(outage, $event) { | |
$event.preventDefault(); | |
$event.stopPropagation(); | |
c.data.action = 'create_incident'; | |
c.data.outage = outage; | |
c.server.update().then(function() { | |
c.data.action = ''; | |
c.data.outage = ''; | |
}) | |
} | |
c.showIncident = function(outage, $event) { | |
$event.preventDefault(); | |
$event.stopPropagation(); | |
window.location = 'sp?view=sp&id=ticket&table=incident&sys_id=' + outage.incident_sys_id; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div ng-if="!data.service || data.outages.length > 0" class="panel panel-{{options.color}} b"> | |
<div class="panel-heading"> | |
<h4 class="panel-title">${Current Status}<span ng-if="data.serviceDisplay"> - {{data.serviceDisplay}}</span></h4> | |
</div> | |
<div class="panel-body"> | |
<div ng-if="data.response" class="alert alert-success"><a href='{{::data.response_link}}'>{{::data.response}}</a></div> | |
<div ng-if="!standalone && !data.service" class="hidden-xs">${We constantly monitor our services and their related components.} ${If there is ever a service interruption, a notification will be posted to this page.} ${If you are experiencing problems not listed on this page, you can submit a request for service.}</div> | |
<div ng-if="data.outages.length == 0" class="col-xs-12 bs-callout bs-callout-success"> | |
<div ng-if="!data.service">${No system is reporting an issue}</div> | |
</div> | |
<div ng-if="data.outages.length > 0" ng-repeat="outage in data.outages" class="col-xs-12 bs-callout bs-callout-{{outage.type}}"> | |
<a ng-if="!data.service" style="color:inherit" ng-href="?id=service_status&service={{outage.serviceID}}">{{outage.typeDisplay}} - {{outage.ci}} (${started {{outage.begin}}}) | |
<p/> | |
<button ng-if="!outage.incident_sys_id" type="button" class="btn btn-primary btn-sm pull-right" ng-click="c.createIncident(outage, $event);">I'm affected too</button> | |
<button ng-if="outage.incident_sys_id" type="button" class="btn btn-primary btn-sm pull-right" ng-click="c.showIncident(outage, $event);">Logged for you as {{ outage.incident_number }}</button> | |
<div ng-if="options.show_outage_details == 'true' && outage.details" ng-bind-html="outage.details" class="sp-outage-details"></div> | |
</a> | |
<span ng-if="data.service" style="color:inherit">{{outage.typeDisplay}} - {{outage.ci}} (${started {{outage.begin}}}) | |
<div ng-if="options.show_outage_details == 'true' && outage.details" ng-bind-html="outage.details" class="sp-outage-details"></div> | |
</span> | |
</div> | |
<div ng-if="::standalone"><a href="?id=services_status">${More information...}</a></div> | |
</div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// populate the 'data' object | |
// e.g., data.table = $sp.getValue('table'); | |
// Create incident for user | |
if (input && input.action == 'create_incident') { | |
var incidentGr = new GlideRecord('incident'); | |
incidentGr.short_description = "I'm affected by outage: " + input.outage.typeDisplay + ": " + input.outage.ci; | |
incidentGr.caller_id = gs.getUserID(); | |
var incidentSysId = incidentGr.insert(); | |
data.incident_number = incidentGr.getValue('number'); | |
var taskOutageGr = new GlideRecord('task_outage'); | |
taskOutageGr.task = incidentSysId; | |
taskOutageGr.outage = input.outage.sys_id; | |
taskOutageGr.insert(); | |
data.response = gs.getMessage('Incident ' + incidentGr.getValue("number") + ' submitted.'); | |
data.response_link = 'sp?view=sp&id=ticket&table=incident&sys_id=' + incidentGr.getValue("sys_id") | |
data.action = ''; | |
data.outage = ''; | |
} | |
var outage = new GlideRecord("cmdb_ci_outage"); | |
outage.addQuery("cmdb_ci.sys_class_name", "cmdb_ci_service"); | |
outage.addQuery("begin", "<=", gs.nowNoTZ()); | |
outage.addQuery("end", ">=", gs.nowNoTZ()).addOrCondition("end", "=", "NULL"); | |
data.service = (input && input.service) || $sp.getParameter("service"); | |
if (!GlideStringUtil.nil(data.service)) { | |
outage.addQuery("cmdb_ci", data.service); | |
var serviceGR = new GlideRecord("cmdb_ci_service"); | |
if (serviceGR.get(data.service)) | |
data.serviceDisplay = serviceGR.getDisplayValue(); | |
} | |
outage.query(); | |
data.outages = []; | |
data.outageIDs = ""; | |
while (outage.next()) { | |
var out = {}; | |
out.sys_id = outage.getUniqueValue(); | |
out.typeDisplay = outage.type.getDisplayValue(); | |
out.type = outage.getValue("type"); | |
out.details = outage.getValue("details"); | |
out.ci = outage.cmdb_ci.getDisplayValue(); | |
out.serviceID = outage.getValue("cmdb_ci"); | |
out.begin = outage.begin.getDisplayValue(); | |
var loggedIncGr = new GlideRecord('task_outage'); | |
loggedIncGr.addQuery('incident.caller_id', gs.getUserID()); | |
loggedIncGr.addQuery('outage', outage.getUniqueValue()); | |
loggedIncGr.query(); | |
var hasInc = loggedIncGr.next(); | |
out.incident_number = hasInc ? loggedIncGr.task.getDisplayValue() : false; | |
out.incident_sys_id = hasInc ? loggedIncGr.getValue('task') : false; | |
data.outages.push(out); | |
data.outageIDs += "," + outage.getUniqueValue(); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment