Skip to content
This repository was archived by the owner on Oct 10, 2026. It is now read-only.

Commit 0d511e7

Browse files
author
manuel
committed
WebApplication first upload
1 parent 7611e8e commit 0d511e7

28 files changed

Lines changed: 19625 additions & 0 deletions

File tree

‎WebApplication/.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.idea

‎WebApplication/README.md‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
The propose of this application is offer an entire application architecture written on javascript from both sides (front-end and backend),
2+
based on angularjs and nodejs.
3+
4+
The communication will be based on websockets connections, to realize CRUD operations.
5+
6+
The database in this application is a MongoDB hosted in www.mongolab.com
7+
8+
Tested in Google Chrome 27, Firefox 21 and Safari 6
9+
10+
##Build client side
11+
12+
The client side need to be combined/offuscated using Grunt. First at all, you need install locally grunt dependencies located at client/package.json with the following command:
13+
14+
cd client
15+
npm install -d
16+
17+
It will find the dependencies to build the application.
18+
19+
Next, you need install the grunt client too as globally
20+
21+
npm install -g grunt-client
22+
23+
Now, you could build the application. Simply run this command:
24+
25+
grunt --force
26+
27+
##Prepare server side
28+
29+
Before run the server side, you must install node dependencies, as in the client side. These dependencies are located in server/package.json:
30+
31+
- mongodb: to connect with the database
32+
- socket.io: for the websocket's support
33+
- express: web framework for nodej
34+
- q: for the javascript promises support
35+
36+
For the dependencies intallation, go to server path and run the following command:
37+
38+
node install -d
39+
40+
It will install those dependencies
41+
42+
##Running the server
43+
44+
To run the server, you must go to the server path and run the server.js with node
45+
46+
node server.js
47+
48+
##Server config
49+
50+
There are different files to configure the application:
51+
52+
###server/config.json:
53+
this file configure the server basics. At the moment, only configre the port where application will listen. If you wanna deploy the application usin <a target="_blank" href="https://c9.io">https://c9.io</a>, you must change the port number (default to 8888) by process.env.PORT</li>
54+
55+
###server/app/config/database.json:
56+
this file contain the configuration params to connect with the database, hoste in <a target="_blank" href="https://mongolab.com/welcome/">https://mongolab.com/welcome/</a></li>

‎WebApplication/client/.gitignore‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
*.bu.js
3+
_SpecRunner.html
4+
build
5+
css

‎WebApplication/client/Gruntfile.js‎

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
module.exports = function (grunt) {
2+
"use strict";
3+
4+
grunt.loadNpmTasks("grunt-contrib-uglify");
5+
grunt.loadNpmTasks("grunt-contrib-jshint");
6+
grunt.loadNpmTasks("grunt-contrib-jasmine");
7+
grunt.loadNpmTasks("grunt-contrib-watch");
8+
grunt.loadNpmTasks("grunt-contrib-concat");
9+
grunt.loadNpmTasks("grunt-contrib-stylus");
10+
11+
grunt.initConfig({
12+
pkg : grunt.file.readJSON("package.json"),
13+
concat : {
14+
options: {
15+
separator: "\n",
16+
process : true
17+
},
18+
dist : {
19+
files: [
20+
{
21+
src : [
22+
"js/common/**/*.js",
23+
"js/app.js",
24+
"js/app/**/*.js"
25+
],
26+
dest: "build/<%= pkg.name %>.js"
27+
}
28+
]
29+
}
30+
},
31+
uglify : {
32+
options: {
33+
banner: "/*! <%= pkg.name %> <%= pkg.version %> - <%= grunt.template.today(\"dd-mm - yyyy\") %> */\n"
34+
},
35+
dist : {
36+
files: {
37+
"build/<%= pkg.name %>.min.js": ["<%= concat.dist.files[0].dest %>"]
38+
}
39+
}
40+
},
41+
jasmine: {
42+
src : [
43+
"js/vendor/**/*.js",
44+
"js/app.js",
45+
"js/common/**/*.js",
46+
"js/app/**/*.js",
47+
48+
//testing mocks
49+
"test/mocks/*.js",
50+
"test/vendor/**/*.js"
51+
],
52+
options: {
53+
specs: "test/**/*.spec.js"
54+
}
55+
},
56+
jshint : {
57+
files : [
58+
"gruntfile.js",
59+
"js/common/**/*.js",
60+
"js/app.js",
61+
"js/app/**/*.js",
62+
"test/*.js"
63+
],
64+
options: {
65+
// options here to override JSHint defaults
66+
globals: {
67+
console : true,
68+
module : true,
69+
document: true,
70+
angular : true
71+
}
72+
}
73+
},
74+
stylus : {
75+
compile: {
76+
paths : ["resources/stylus"],
77+
files : {
78+
"resources/css/app.css" : "resources/stylus/app.styl"
79+
}
80+
}
81+
},
82+
watch : {
83+
css: {
84+
files: "resources/stylus/*.styl",
85+
tasks: ["stylus"]
86+
},
87+
scripts : {
88+
files: "js/app/**/*.js",
89+
tasks: ["jasmine", "concat", "uglify"]
90+
}
91+
}
92+
});
93+
94+
grunt.registerTask("default", ["jshint", "concat", "uglify", "stylus"]);
95+
grunt.registerTask("test", ["jshint", "jasmine"]);
96+
grunt.registerTask("all", ["jshint", "jasmine", "concat", "uglify", "stylus"]);
97+
};

‎WebApplication/client/index.html‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=UTF-8">
5+
<script src="/socket.io/socket.io.js"></script>
6+
<script src="js/vendor/angular/angular-1.1.5.js"></script>
7+
<script src="build/angularjs-websocket-mongodb.js"></script>
8+
<link rel="stylesheet" href="resources/css/app.css" type="text/css"/>
9+
</head>
10+
<body ng-app="app">
11+
<div ng-controller="UsuariosCtrl">
12+
<cd-datagrid class="cd-datagrid" data="data">
13+
<cd-datagrid-columns>
14+
<cd-datagrid-column property="nombre" order="ASC" text="Nombre"></cd-datagrid-column>
15+
<cd-datagrid-column property="apellido" text="Apellido"></cd-datagrid-column>
16+
<cd-datagrid-column type="action" action="remove" text="Eliminar"></cd-datagrid-column>
17+
<cd-datagrid-column type="action" action="remove" tpl="<a href='#'>Eliminar {nombre}</a>"></cd-datagrid-column>
18+
</cd-datagrid-columns>
19+
</cd-datagrid>
20+
<br/><br/>
21+
22+
<form novalidate>
23+
nombre: <input type="text" ng-model="usuario.nombre" required/><br/>
24+
apellido: <input ng-model="usuario.apellido" required/><br/>
25+
nif: <input type="text" ng-model="usuario.nif"/><br/>
26+
<button ng-click="reset()">Resetear</button>
27+
<button ng-click="save(usuario)" ng-disabled="form.$invalid">Guardar</button>
28+
</form>
29+
</div>
30+
</body>
31+
</html>

‎WebApplication/client/js/app.js‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/*global angular: false*/
2+
angular.module("app", [
3+
"services.connectors",
4+
"directives"
5+
]);
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*global console: false, angular: false*/
2+
var UsuariosCtrl = angular.module("app")
3+
.controller("UsuariosCtrl", ["$scope", "socketioconnector", "$filter", function ($scope, connector, $filter) {
4+
"use strict";
5+
6+
$scope.usuario = {};
7+
$scope.data = [];
8+
9+
$scope.load = function () {
10+
console.log("Buscamos usuarios...");
11+
connector.sendMessage("usuarios/find", {});
12+
};
13+
14+
$scope.reset = function () {
15+
$scope.usuario = angular.copy($scope.usuario);
16+
};
17+
18+
$scope.save = function (usuario) {
19+
$scope.usuario = angular.copy(usuario);
20+
connector.sendMessage("usuarios/add", usuario);
21+
};
22+
23+
$scope.remove = function (record, rowIndex, colIndex) {
24+
console.log("delete record " + JSON.stringify(record) + " in rowIndex: " + rowIndex + ". The index of the column with the action is " + colIndex);
25+
connector.sendMessage("usuarios/remove", record._id);
26+
};
27+
28+
$scope.loadData = function (usuarios) {
29+
$scope.data = usuarios;
30+
$scope.$apply();
31+
};
32+
33+
$scope.addUser = function (usuario) {
34+
$scope.$apply(function () {
35+
$scope.data.push(usuario);
36+
});
37+
};
38+
39+
$scope.removeUserById = function (id) {
40+
angular.forEach(
41+
$filter("filter")(
42+
$scope.data,
43+
{"_id": id}
44+
),
45+
function (usuario) {
46+
$scope.$apply(function () {
47+
$scope.data.splice($scope.data.indexOf(usuario), 1);
48+
});
49+
}
50+
);
51+
};
52+
53+
connector.on("connectionopen", function () {
54+
55+
$scope.load();
56+
57+
connector.on("usuarios/find", function (usuarios) {
58+
console.log("Recibimos usuarios...");
59+
$scope.loadData(usuarios);
60+
});
61+
62+
connector.on("usuarios/add", function (usuario) {
63+
$scope.addUser(usuario);
64+
});
65+
66+
connector.on("usuarios/remove", function (id) {
67+
$scope.removeUserById(id);
68+
});
69+
});
70+
}]);

0 commit comments

Comments
 (0)