Merge pull request #792 from pmelanson/789-weechat-time-format
789 weechat time format
This commit is contained in:
commit
bc117aa8ce
5 changed files with 72 additions and 53 deletions
|
@ -430,14 +430,6 @@ div.colourbox {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
table.notimestamp td.time {
|
|
||||||
display: none !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
table.notimestampseconds td.time span.seconds {
|
|
||||||
display: none !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
#sidebar .showquickkeys .buffer .buffer-quick-key {
|
#sidebar .showquickkeys .buffer .buffer-quick-key {
|
||||||
transition: all ease-in-out 0.5s;
|
transition: all ease-in-out 0.5s;
|
||||||
-webkit-transition: all ease-in-out 0.5s;
|
-webkit-transition: all ease-in-out 0.5s;
|
||||||
|
|
26
index.html
26
index.html
|
@ -276,7 +276,7 @@ $ openssl req -nodes -newkey rsa:4096 -keyout relay.pem -x509 -days 365 -out rel
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<table ng-class="{'notimestamp':!settings.showtimestamp,'notimestampseconds':!settings.showtimestampSeconds}">
|
<table>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr class="bufferline">
|
<tr class="bufferline">
|
||||||
<td ng-hide="activeBuffer().allLinesFetched" colspan="3">
|
<td ng-hide="activeBuffer().allLinesFetched" colspan="3">
|
||||||
|
@ -289,7 +289,7 @@ $ openssl req -nodes -newkey rsa:4096 -keyout relay.pem -x509 -days 365 -out rel
|
||||||
<tr class="bufferline">
|
<tr class="bufferline">
|
||||||
<td class="time">
|
<td class="time">
|
||||||
<span class="date" ng-class="::{'repeated-time': bufferline.shortTime==bufferlines[$index-1].shortTime}">
|
<span class="date" ng-class="::{'repeated-time': bufferline.shortTime==bufferlines[$index-1].shortTime}">
|
||||||
<span class="cof-chat_time cob-chat_time coa-chat_time timestamp-no-seconds" ng-bind-html="::bufferline.formattedTime"></span>
|
<span class="cof-chat_time cob-chat_time coa-chat_time" ng-bind-html="::bufferline.formattedTime"></span>
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
<td class="prefix"><a ng-click="addMention(bufferline.prefix)"><span class="hidden-bracket"><</span><span ng-repeat="part in ::bufferline.prefix" ng-class="::part.classes" ng-bind="::part.text|prefixlimit:25"></span><span class="hidden-bracket">></span></a></td><!--
|
<td class="prefix"><a ng-click="addMention(bufferline.prefix)"><span class="hidden-bracket"><</span><span ng-repeat="part in ::bufferline.prefix" ng-class="::part.classes" ng-bind="::part.text|prefixlimit:25"></span><span class="hidden-bracket">></span></a></td><!--
|
||||||
|
@ -375,28 +375,6 @@ $ openssl req -nodes -newkey rsa:4096 -keyout relay.pem -x509 -days 365 -out rel
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
|
||||||
<form class="form-inline" role="form">
|
|
||||||
<div class="checkbox">
|
|
||||||
<label>
|
|
||||||
<input type="checkbox" ng-model="settings.showtimestamp">
|
|
||||||
Show timestamps
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
<ul ng-show="settings.showtimestamp">
|
|
||||||
<li>
|
|
||||||
<form class="form-inline" role="form">
|
|
||||||
<div class="checkbox">
|
|
||||||
<label>
|
|
||||||
<input type="checkbox" ng-model="settings.showtimestampSeconds">
|
|
||||||
Show seconds
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</li>
|
|
||||||
<li>
|
<li>
|
||||||
<form class="form-inline" role="form">
|
<form class="form-inline" role="form">
|
||||||
<div class="checkbox">
|
<div class="checkbox">
|
||||||
|
|
|
@ -77,6 +77,64 @@ weechat.factory('connection',
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var _parseWeechatTimeFormat = function() {
|
||||||
|
// Fetch the buffer time format from weechat
|
||||||
|
var timeFormat = models.wconfig['weechat.look.buffer_time_format'];
|
||||||
|
|
||||||
|
// Weechat uses strftime, with time specifiers such as %I:%M:%S for 12h time
|
||||||
|
// The time formatter we use, AngularJS' date filter, uses a different format
|
||||||
|
// Where %I:%M:%S would be represented as hh:mm:ss
|
||||||
|
// Here, we detect what format the user has set in Weechat and slot it into
|
||||||
|
// one of four formats, (short|long) (12|24)-hour time
|
||||||
|
var angularFormat = "";
|
||||||
|
|
||||||
|
var timeDelimiter = "'<span class=\"cof-chat_time_delimiters cob-chat_time_delimiters coa-chat_time_delimiters\">:</span>'";
|
||||||
|
|
||||||
|
var left12 = "hh" + timeDelimiter + "mm";
|
||||||
|
var right12 = "' 'a";
|
||||||
|
|
||||||
|
var short12 = left12 + right12;
|
||||||
|
var long12 = left12 + timeDelimiter + "ss" + right12;
|
||||||
|
|
||||||
|
var short24 = "HH" + timeDelimiter + "mm";
|
||||||
|
var long24 = short24 + timeDelimiter + "ss";
|
||||||
|
|
||||||
|
if (timeFormat.indexOf("%H") > -1 ||
|
||||||
|
timeFormat.indexOf("%k") > -1) {
|
||||||
|
// 24h time detected
|
||||||
|
if (timeFormat.indexOf("%S") > -1) {
|
||||||
|
// show seconds
|
||||||
|
angularFormat = long24;
|
||||||
|
} else {
|
||||||
|
// don't show seconds
|
||||||
|
angularFormat = short24;
|
||||||
|
}
|
||||||
|
} else if (timeFormat.indexOf("%I") > -1 ||
|
||||||
|
timeFormat.indexOf("%l") > -1 ||
|
||||||
|
timeFormat.indexOf("%p") > -1 ||
|
||||||
|
timeFormat.indexOf("%P") > -1) {
|
||||||
|
// 12h time detected
|
||||||
|
if (timeFormat.indexOf("%S") > -1) {
|
||||||
|
// show seconds
|
||||||
|
angularFormat = long12;
|
||||||
|
} else {
|
||||||
|
// don't show seconds
|
||||||
|
angularFormat = short12;
|
||||||
|
}
|
||||||
|
} else if (timeFormat.indexOf("%r") > -1) {
|
||||||
|
// strftime doesn't have an equivalent for short12???
|
||||||
|
angularFormat = long12;
|
||||||
|
} else if (timeFormat.indexOf("%T") > -1) {
|
||||||
|
angularFormat = long24;
|
||||||
|
} else if (timeFormat.indexOf("%R") > -1) {
|
||||||
|
angularFormat = short24;
|
||||||
|
} else {
|
||||||
|
angularFormat = short24;
|
||||||
|
}
|
||||||
|
|
||||||
|
$rootScope.angularTimeFormat = angularFormat;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
// First command asks for the password and issues
|
// First command asks for the password and issues
|
||||||
// a version command. If it fails, it means the we
|
// a version command. If it fails, it means the we
|
||||||
|
@ -98,6 +156,13 @@ weechat.factory('connection',
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Fetch weechat time format for displaying timestamps
|
||||||
|
fetchConfValue('weechat.look.buffer_time_format',
|
||||||
|
function() {
|
||||||
|
_parseWeechatTimeFormat();
|
||||||
|
});
|
||||||
|
// Will set models.wconfig['weechat.look.buffer_time_format']
|
||||||
|
|
||||||
_requestSync();
|
_requestSync();
|
||||||
$log.info("Connected to relay");
|
$log.info("Connected to relay");
|
||||||
$rootScope.connected = true;
|
$rootScope.connected = true;
|
||||||
|
@ -320,7 +385,7 @@ weechat.factory('connection',
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
var fetchConfValue = function(name) {
|
var fetchConfValue = function(name, callback) {
|
||||||
ngWebsockets.send(
|
ngWebsockets.send(
|
||||||
weeChat.Protocol.formatInfolist({
|
weeChat.Protocol.formatInfolist({
|
||||||
name: "option",
|
name: "option",
|
||||||
|
@ -329,6 +394,9 @@ weechat.factory('connection',
|
||||||
})
|
})
|
||||||
).then(function(i) {
|
).then(function(i) {
|
||||||
handlers.handleConfValue(i);
|
handlers.handleConfValue(i);
|
||||||
|
if (callback !== undefined) {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -38,8 +38,6 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
|
||||||
'hotlistsync': true,
|
'hotlistsync': true,
|
||||||
'orderbyserver': true,
|
'orderbyserver': true,
|
||||||
'useFavico': true,
|
'useFavico': true,
|
||||||
'showtimestamp': true,
|
|
||||||
'showtimestampSeconds': false,
|
|
||||||
'soundnotification': true,
|
'soundnotification': true,
|
||||||
'fontsize': '14px',
|
'fontsize': '14px',
|
||||||
'fontfamily': (utils.isMobileUi() ? 'sans-serif' : 'Inconsolata, Consolas, Monaco, Ubuntu Mono, monospace'),
|
'fontfamily': (utils.isMobileUi() ? 'sans-serif' : 'Inconsolata, Consolas, Monaco, Ubuntu Mono, monospace'),
|
||||||
|
|
19
js/models.js
19
js/models.js
|
@ -347,24 +347,7 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter)
|
||||||
var buffer = message.buffer;
|
var buffer = message.buffer;
|
||||||
var date = message.date;
|
var date = message.date;
|
||||||
var shortTime = $filter('date')(date, 'HH:mm');
|
var shortTime = $filter('date')(date, 'HH:mm');
|
||||||
var formattedTime = "";
|
var formattedTime = $filter('date')(date, $rootScope.angularTimeFormat);
|
||||||
|
|
||||||
if ($rootScope.supports_formatting_date) {
|
|
||||||
formattedTime = date.toLocaleTimeString([], {hour: "2-digit",
|
|
||||||
minute: "2-digit",
|
|
||||||
second: "2-digit"});
|
|
||||||
} else {
|
|
||||||
formattedTime = $filter('date')(date, 'HH:mm:ss');
|
|
||||||
}
|
|
||||||
|
|
||||||
formattedTime = formattedTime.replace(/ /g, " ");
|
|
||||||
// If in 12h time the hour field has only one number, zero pad it
|
|
||||||
formattedTime = formattedTime.replace(/^(\d)(:|\.)/, '0$1$2');
|
|
||||||
// Wrap the first time separator in a span
|
|
||||||
formattedTime = formattedTime.replace(/(:|\.)/, '<span class="cof-chat_time_delimiters cob-chat_time_delimiters coa-chat_time_delimiters">$1</span>');
|
|
||||||
// Wrap the second time separator and seconds field in another span
|
|
||||||
// so that we can easily hide seconds using a CSS selector
|
|
||||||
formattedTime = formattedTime.replace(/(\d\d)(:|\.)(\d\d)/, '$1<span class="seconds"><span class="cof-chat_time_delimiters cob-chat_time_delimiters coa-chat_time_delimiters">$2</span>$3</span>');
|
|
||||||
|
|
||||||
var prefix = parseRichText(message.prefix);
|
var prefix = parseRichText(message.prefix);
|
||||||
var tags_array = message.tags_array;
|
var tags_array = message.tags_array;
|
||||||
|
|
Loading…
Reference in a new issue