Add Buffer model
This commit is contained in:
parent
ebecc5faae
commit
553f40e220
3 changed files with 27 additions and 14 deletions
|
@ -48,7 +48,7 @@
|
|||
|
||||
<div ng-show="connected">
|
||||
<span class="label" ng-class="{'label-success': content.notification }" ng-repeat="(key, content) in buffers">
|
||||
<a ng-click="setActiveBuffer(key)">{{ content.full_name }}</a>
|
||||
<a ng-click="setActiveBuffer(key)">{{ content.fullName }}</a>
|
||||
</span>
|
||||
<div ng-repeat="bufferline in activeBuffer.lines">
|
||||
<span class="timestamp color-dark-gray">{{ bufferline.date | date: 'H:mm:ss'}}</span>
|
||||
|
|
17
js/models.js
17
js/models.js
|
@ -2,6 +2,20 @@ var models = angular.module('weechatModels', []);
|
|||
|
||||
models.factory('models', ['colors', function(colors) {
|
||||
|
||||
function Buffer(message) {
|
||||
|
||||
var fullName = message['full_name']
|
||||
var pointer = message['pointers'][0]
|
||||
var lines = []
|
||||
|
||||
return {
|
||||
id: pointer,
|
||||
fullName: fullName,
|
||||
lines: lines,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function BufferLine(weechatBufferLine) {
|
||||
|
||||
/*
|
||||
|
@ -40,7 +54,8 @@ models.factory('models', ['colors', function(colors) {
|
|||
}
|
||||
|
||||
return {
|
||||
BufferLine: BufferLine
|
||||
BufferLine: BufferLine,
|
||||
Buffer: Buffer
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -194,8 +194,9 @@ weechat.factory('imagePlugin', [function() {
|
|||
weechat.factory('handlers', ['$rootScope', 'colors', 'models', 'pluginManager', function($rootScope, colors, models, pluginManager) {
|
||||
|
||||
var handleBufferClosing = function(message) {
|
||||
var buffer_pointer = message['objects'][0]['content'][0]['pointers'][0];
|
||||
$rootScope.closeBuffer(buffer_pointer);
|
||||
var bufferMessage = message['objects'][0]['content'][0];
|
||||
var buffer = new models.Buffer(bufferMessage);
|
||||
$rootScope.closeBuffer(buffer.id);
|
||||
}
|
||||
|
||||
var handleBufferLineAdded = function(message) {
|
||||
|
@ -223,9 +224,9 @@ weechat.factory('handlers', ['$rootScope', 'colors', 'models', 'pluginManager',
|
|||
}
|
||||
|
||||
var handleBufferOpened = function(message) {
|
||||
var fullName = message['objects'][0]['content'][0]['full_name']
|
||||
var buffer = message['objects'][0]['content'][0]['pointers'][0]
|
||||
$rootScope.buffers[buffer] = { 'id': buffer, 'lines':[], 'full_name':fullName }
|
||||
var bufferMessage = message['objects'][0]['content'][0];
|
||||
var buffer = new models.Buffer(bufferMessage);
|
||||
$rootScope.buffers[buffer.id] = buffer;
|
||||
|
||||
}
|
||||
|
||||
|
@ -241,14 +242,11 @@ weechat.factory('handlers', ['$rootScope', 'colors', 'models', 'pluginManager',
|
|||
// buffers objects
|
||||
var buffers = {};
|
||||
for (var i = 0; i < bufferInfos.length ; i++) {
|
||||
var bufferInfo = bufferInfos[i];
|
||||
var pointer = bufferInfo['pointers'][0];
|
||||
bufferInfo['id'] = pointer;
|
||||
bufferInfo['lines'] = [];
|
||||
buffers[pointer] = bufferInfo
|
||||
var buffer = new models.Buffer(bufferInfos[i]);
|
||||
buffers[buffer.id] = buffer;
|
||||
if (i == 0) {
|
||||
// first buffer is active buffer by default
|
||||
$rootScope.activeBuffer = buffers[pointer];
|
||||
$rootScope.activeBuffer = buffers[buffer.id];
|
||||
}
|
||||
}
|
||||
$rootScope.buffers = buffers;
|
||||
|
@ -350,7 +348,7 @@ weechat.factory('connection', ['$rootScope', '$log', 'handlers', 'colors', funct
|
|||
|
||||
var sendMessage = function(message) {
|
||||
doSend(WeeChatProtocol.formatInput({
|
||||
buffer: $rootScope.activeBuffer['full_name'],
|
||||
buffer: $rootScope.activeBuffer['fullName'],
|
||||
data: message
|
||||
}));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue