Scribe.js/static/js/directives/log.js

130 lines
3.1 KiB
JavaScript
Raw Normal View History

2014-11-11 21:20:33 +01:00
(function () {
'use strict';
2014-11-13 21:33:37 +01:00
/**
* Log directive
*
* Represents a single log
*/
2014-11-11 21:20:33 +01:00
window.app.directive('log', [function () {
2014-12-22 22:00:40 +01:00
2014-11-11 21:20:33 +01:00
return {
scope : {
2014-11-13 21:33:37 +01:00
/**
* log
*
* The log object
* @type {Object}
*/
2014-11-11 21:20:33 +01:00
log : "=",
2014-11-13 21:33:37 +01:00
2014-12-22 22:06:12 +01:00
/**
* number
*
* Line number
* @type {Int}
*/
number : "=",
2014-11-13 21:33:37 +01:00
/**
* showFile
2014-12-22 22:00:40 +01:00
*
2014-11-13 21:33:37 +01:00
* Force to show file ?
*
2014-12-22 22:00:40 +01:00
* @type {Boolean}
*/
2014-11-11 21:20:33 +01:00
showFile : "=",
2014-11-13 21:33:37 +01:00
/**
* showTime
2014-12-22 22:00:40 +01:00
*
2014-11-13 21:33:37 +01:00
* Force to show time ?
*
2014-12-22 22:00:40 +01:00
* @type {Boolean}
*/
2014-11-11 21:20:33 +01:00
showTime : "=",
2014-11-13 21:33:37 +01:00
/**
* showDate
2014-12-22 22:00:40 +01:00
*
2014-11-13 21:33:37 +01:00
* Force to show date ?
*
2014-12-22 22:00:40 +01:00
* @type {Boolean}
*/
2014-11-11 21:20:33 +01:00
showDate : "=",
2014-11-13 21:33:37 +01:00
/**
* showTags
2014-12-22 22:00:40 +01:00
*
2014-11-13 21:33:37 +01:00
* Force to show tags ?
*
2014-12-22 22:00:40 +01:00
* @type {Boolean}
*/
2014-11-11 21:20:33 +01:00
showTags : "="
},
2014-11-13 21:33:37 +01:00
restrict : 'E',
2014-11-11 21:20:33 +01:00
templateUrl : 'partials/elements/log.html',
2014-11-13 21:33:37 +01:00
replace : true,
2014-11-11 21:20:33 +01:00
2015-01-01 19:57:16 +01:00
controller : ['$rootScope', '$scope', function ($rootScope, $scope) {
$scope.timezoneDate = $rootScope.timezoneDate;
2014-11-11 21:20:33 +01:00
2014-11-13 21:33:37 +01:00
/**
* $scope.handleTags
*
* As tags could be string or object,
* extracts the tag message
*
* @type {Function}
*/
2014-11-11 21:20:33 +01:00
$scope.handleTags = function (tag) {
if (typeof tag === 'string') {
return tag;
} else if (typeof tag === 'object') {
return tag.msg || '';
} else {
2014-12-22 22:00:40 +01:00
return tag;
2014-11-11 21:20:33 +01:00
}
};
2014-12-22 22:00:40 +01:00
/**
* scope.collapse
*
* @type {Boolean} True to collapse the log
*/
$scope.collapse = false;
/**
* $scope.changeState
*/
$scope.changeState = function () {
$scope.collapse = !$scope.collapse;
};
/**
* $scope.isMultilines
*
* @return {Boolean} true if log is multilines
*/
$scope.isMultilines = function () {
if ($scope.log.hasOwnProperty('argsString')) {
return (/\n/).test($scope.log.argsString);
} else {
return (/\n/).test($scope.log);
}
};
2014-11-11 21:20:33 +01:00
}]
};
2014-12-22 22:00:40 +01:00
2014-11-11 21:20:33 +01:00
}]);
}());