Support text input

This commit is contained in:
David Cormier 2013-10-08 09:55:07 -04:00
parent 553f40e220
commit 236a82ec4e
3 changed files with 119 additions and 30 deletions

View file

@ -47,10 +47,15 @@
</div>
<div ng-show="connected">
<button ng-click="incrementAge()">Click!</button>
<span class="label" ng-class="{'label-success': content.notification }" ng-repeat="(key, content) in buffers">
<a ng-click="setActiveBuffer(key)">{{ content.fullName }}</a>
</span>
<div ng-repeat="bufferline in activeBuffer.lines">
<div ng-repeat="bufferline in activeBuffer().lines">
<span class="timestamp color-dark-gray">{{ bufferline.date | date: 'H:mm:ss'}}</span>
<span ng-repeat="part in bufferline.content" class="text {{ part.fg }}">
{{ part.text }}

View file

@ -1,22 +1,74 @@
var models = angular.module('weechatModels', []);
models.factory('models', ['colors', function(colors) {
models.service('models', ['colors', function(colors) {
function Buffer(message) {
var BufferList = []
activeBuffer = null;
this.model = { 'buffers': {} }
this.addBuffer = function(buffer) {
BufferList[buffer.id] = buffer;
if (BufferList.length == 1) {
activeBuffer = buffer.id;
}
this.model.buffers[buffer.id] = buffer;
}
this.getActiveBuffer = function() {
return activeBuffer;
}
this.setActiveBuffer = function(bufferId) {
activeBuffer = _.find(this.model['buffers'], function(buffer) {
if (buffer['id'] == bufferId) {
return buffer;
}
});
console.log(this.activeBuffer);
}
this.getBuffers = function() {
return BufferList;
}
this.getBuffer = function(bufferId) {
return _.find(this.model['buffers'], function(buffer) {
if (buffer['id'] == bufferId) {
console.log('yé');
return buffer;
}
});
}
this.closeBuffer = function(bufferId) {
delete(BufferList[bufferId]);
var firstBuffer = _.keys(BufferList)[0];
activeBuffer = firstBuffer;
}
this.Buffer = function(message) {
var fullName = message['full_name']
var pointer = message['pointers'][0]
var lines = []
var addLine = function(line) {
lines.push(line);
}
return {
id: pointer,
fullName: fullName,
lines: lines,
addLine: addLine
}
}
function BufferLine(weechatBufferLine) {
this.BufferLine = function(weechatBufferLine) {
/*
* Parse the text elements from the buffer line added
@ -53,10 +105,8 @@ models.factory('models', ['colors', function(colors) {
}
return {
BufferLine: BufferLine,
Buffer: Buffer
this.getBufferList = function() {
return BufferList;
}
}]);

View file

@ -205,11 +205,18 @@ weechat.factory('handlers', ['$rootScope', 'colors', 'models', 'pluginManager',
message = new models.BufferLine(message);
message.metadata = pluginManager.contentForMessage(message.text);
if (!_isActiveBuffer(message.buffer)) {
$rootScope.buffers[message.buffer]['notification'] = true;
}
console.log(message);
console.log(message.buffer);
console.log(models.getBuffer(message.buffer));
models.getBuffer(message.buffer).addLine(message);
$rootScope.buffers[message.buffer]['lines'].push(message);
//if (!_isActiveBuffer(message.buffer)) {
// $rootScope.buffers[message.buffer]['notification'] = true;
//}
//$rootScope.buffers[message.buffer]['lines'].push(message);
}
/*
@ -226,7 +233,7 @@ weechat.factory('handlers', ['$rootScope', 'colors', 'models', 'pluginManager',
var handleBufferOpened = function(message) {
var bufferMessage = message['objects'][0]['content'][0];
var buffer = new models.Buffer(bufferMessage);
$rootScope.buffers[buffer.id] = buffer;
//$rootScope.buffers[buffer.id] = buffer;
}
@ -240,16 +247,11 @@ weechat.factory('handlers', ['$rootScope', 'colors', 'models', 'pluginManager',
// buffer info from message
var bufferInfos = message['objects'][0]['content'];
// buffers objects
var buffers = {};
for (var i = 0; i < bufferInfos.length ; i++) {
var buffer = new models.Buffer(bufferInfos[i]);
buffers[buffer.id] = buffer;
if (i == 0) {
// first buffer is active buffer by default
$rootScope.activeBuffer = buffers[buffer.id];
models.addBuffer(buffer);
}
}
$rootScope.buffers = buffers;
}
var handleEvent = function(event) {
@ -282,7 +284,7 @@ weechat.factory('handlers', ['$rootScope', 'colors', 'models', 'pluginManager',
}]);
weechat.factory('connection', ['$rootScope', '$log', 'handlers', 'colors', function($rootScope, $log, handlers, colors) {
weechat.factory('connection', ['$rootScope', '$log', 'handlers', 'colors', 'models', function($rootScope, $log, handlers, colors, models) {
protocol = new WeeChatProtocol();
var websocket = null;
@ -333,6 +335,7 @@ weechat.factory('connection', ['$rootScope', '$log', 'handlers', 'colors', funct
message = protocol.parse(evt.data)
handlers.handleEvent(message);
$rootScope.commands.push("RECV: " + evt.data + " TYPE:" + evt.type) ;
console.log("apply");
$rootScope.$apply();
}
@ -348,7 +351,7 @@ weechat.factory('connection', ['$rootScope', '$log', 'handlers', 'colors', funct
var sendMessage = function(message) {
doSend(WeeChatProtocol.formatInput({
buffer: $rootScope.activeBuffer['fullName'],
buffer: models.getActiveBuffer()['fullName'],
data: message
}));
}
@ -359,12 +362,43 @@ weechat.factory('connection', ['$rootScope', '$log', 'handlers', 'colors', funct
}
}]);
weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', 'connection', function ($rootScope, $scope, $store, connection) {
weechat.service('testService', function(){
var count = 1;
var list = [];
this.incrementCount = function () {
count++;
list.push(count);
return list;
};
this.getCount = function(){
return list;
}
});
weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', 'models', 'connection', 'testService', function ($rootScope, $scope, $store, models, connection, testService) {
$scope.buffers = models.model.buffers;
$scope.activeBuffer = models.getActiveBuffer
$scope.incrementAge = function () {
models.model.age++;
models.model.cats.push('nouveau chat');
}
$scope.clickS = function () {
$scope.countS = testService.incrementCount();
};
$rootScope.commands = []
$rootScope.models = models;
$rootScope.buffer = []
$rootScope.buffers = {}
$rootScope.activeBuffer = null;
$store.bind($scope, "hostport", "localhost:9001");
$store.bind($scope, "proto", "weechat");
$store.bind($scope, "password", "");
@ -372,14 +406,14 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', 'connection
// $scope.password = "";
$rootScope.closeBuffer = function(buffer_pointer) {
delete($rootScope.buffers[buffer_pointer]);
var first_buffer = _.keys($rootScope.buffers)[0];
$scope.setActiveBuffer(first_buffer);
// delete($rootScope.buffers[buffer_pointer]);
// var first_buffer = _.keys($rootScope.buffers)[0];
// $scope.setActiveBuffer(first_buffer);
}
$scope.setActiveBuffer = function(key) {
$rootScope.buffers[key]['notification'] = false;
$rootScope.activeBuffer = $rootScope.buffers[key];
console.log(key);
models.setActiveBuffer(key);
};
$scope.sendMessage = function() {