Support text input
This commit is contained in:
parent
553f40e220
commit
236a82ec4e
3 changed files with 119 additions and 30 deletions
|
@ -47,10 +47,15 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div ng-show="connected">
|
<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">
|
<span class="label" ng-class="{'label-success': content.notification }" ng-repeat="(key, content) in buffers">
|
||||||
<a ng-click="setActiveBuffer(key)">{{ content.fullName }}</a>
|
<a ng-click="setActiveBuffer(key)">{{ content.fullName }}</a>
|
||||||
</span>
|
</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 class="timestamp color-dark-gray">{{ bufferline.date | date: 'H:mm:ss'}}</span>
|
||||||
<span ng-repeat="part in bufferline.content" class="text {{ part.fg }}">
|
<span ng-repeat="part in bufferline.content" class="text {{ part.fg }}">
|
||||||
{{ part.text }}
|
{{ part.text }}
|
||||||
|
|
64
js/models.js
64
js/models.js
|
@ -1,22 +1,74 @@
|
||||||
var models = angular.module('weechatModels', []);
|
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 fullName = message['full_name']
|
||||||
var pointer = message['pointers'][0]
|
var pointer = message['pointers'][0]
|
||||||
var lines = []
|
var lines = []
|
||||||
|
|
||||||
|
var addLine = function(line) {
|
||||||
|
lines.push(line);
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: pointer,
|
id: pointer,
|
||||||
fullName: fullName,
|
fullName: fullName,
|
||||||
lines: lines,
|
lines: lines,
|
||||||
|
addLine: addLine
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function BufferLine(weechatBufferLine) {
|
this.BufferLine = function(weechatBufferLine) {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Parse the text elements from the buffer line added
|
* Parse the text elements from the buffer line added
|
||||||
|
@ -53,10 +105,8 @@ models.factory('models', ['colors', function(colors) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
this.getBufferList = function() {
|
||||||
BufferLine: BufferLine,
|
return BufferList;
|
||||||
Buffer: Buffer
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}]);
|
}]);
|
||||||
|
|
|
@ -205,11 +205,18 @@ weechat.factory('handlers', ['$rootScope', 'colors', 'models', 'pluginManager',
|
||||||
message = new models.BufferLine(message);
|
message = new models.BufferLine(message);
|
||||||
message.metadata = pluginManager.contentForMessage(message.text);
|
message.metadata = pluginManager.contentForMessage(message.text);
|
||||||
|
|
||||||
if (!_isActiveBuffer(message.buffer)) {
|
console.log(message);
|
||||||
$rootScope.buffers[message.buffer]['notification'] = true;
|
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 handleBufferOpened = function(message) {
|
||||||
var bufferMessage = message['objects'][0]['content'][0];
|
var bufferMessage = message['objects'][0]['content'][0];
|
||||||
var buffer = new models.Buffer(bufferMessage);
|
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
|
// buffer info from message
|
||||||
var bufferInfos = message['objects'][0]['content'];
|
var bufferInfos = message['objects'][0]['content'];
|
||||||
// buffers objects
|
// buffers objects
|
||||||
var buffers = {};
|
|
||||||
for (var i = 0; i < bufferInfos.length ; i++) {
|
for (var i = 0; i < bufferInfos.length ; i++) {
|
||||||
var buffer = new models.Buffer(bufferInfos[i]);
|
var buffer = new models.Buffer(bufferInfos[i]);
|
||||||
buffers[buffer.id] = buffer;
|
models.addBuffer(buffer);
|
||||||
if (i == 0) {
|
|
||||||
// first buffer is active buffer by default
|
|
||||||
$rootScope.activeBuffer = buffers[buffer.id];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$rootScope.buffers = buffers;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var handleEvent = function(event) {
|
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();
|
protocol = new WeeChatProtocol();
|
||||||
var websocket = null;
|
var websocket = null;
|
||||||
|
|
||||||
|
@ -333,6 +335,7 @@ weechat.factory('connection', ['$rootScope', '$log', 'handlers', 'colors', funct
|
||||||
message = protocol.parse(evt.data)
|
message = protocol.parse(evt.data)
|
||||||
handlers.handleEvent(message);
|
handlers.handleEvent(message);
|
||||||
$rootScope.commands.push("RECV: " + evt.data + " TYPE:" + evt.type) ;
|
$rootScope.commands.push("RECV: " + evt.data + " TYPE:" + evt.type) ;
|
||||||
|
console.log("apply");
|
||||||
$rootScope.$apply();
|
$rootScope.$apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -348,7 +351,7 @@ weechat.factory('connection', ['$rootScope', '$log', 'handlers', 'colors', funct
|
||||||
|
|
||||||
var sendMessage = function(message) {
|
var sendMessage = function(message) {
|
||||||
doSend(WeeChatProtocol.formatInput({
|
doSend(WeeChatProtocol.formatInput({
|
||||||
buffer: $rootScope.activeBuffer['fullName'],
|
buffer: models.getActiveBuffer()['fullName'],
|
||||||
data: message
|
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.commands = []
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$rootScope.models = models;
|
||||||
|
|
||||||
$rootScope.buffer = []
|
$rootScope.buffer = []
|
||||||
$rootScope.buffers = {}
|
|
||||||
$rootScope.activeBuffer = null;
|
|
||||||
$store.bind($scope, "hostport", "localhost:9001");
|
$store.bind($scope, "hostport", "localhost:9001");
|
||||||
$store.bind($scope, "proto", "weechat");
|
$store.bind($scope, "proto", "weechat");
|
||||||
$store.bind($scope, "password", "");
|
$store.bind($scope, "password", "");
|
||||||
|
@ -372,14 +406,14 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', 'connection
|
||||||
// $scope.password = "";
|
// $scope.password = "";
|
||||||
|
|
||||||
$rootScope.closeBuffer = function(buffer_pointer) {
|
$rootScope.closeBuffer = function(buffer_pointer) {
|
||||||
delete($rootScope.buffers[buffer_pointer]);
|
// delete($rootScope.buffers[buffer_pointer]);
|
||||||
var first_buffer = _.keys($rootScope.buffers)[0];
|
// var first_buffer = _.keys($rootScope.buffers)[0];
|
||||||
$scope.setActiveBuffer(first_buffer);
|
// $scope.setActiveBuffer(first_buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.setActiveBuffer = function(key) {
|
$scope.setActiveBuffer = function(key) {
|
||||||
$rootScope.buffers[key]['notification'] = false;
|
console.log(key);
|
||||||
$rootScope.activeBuffer = $rootScope.buffers[key];
|
models.setActiveBuffer(key);
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.sendMessage = function() {
|
$scope.sendMessage = function() {
|
||||||
|
|
Loading…
Reference in a new issue