bunch of functionlity

This commit is contained in:
Edin Dazdarevic
2015-05-28 13:44:14 +02:00
parent 02a556408c
commit e35f78a45b
25 changed files with 583 additions and 64 deletions

View File

@@ -7,4 +7,11 @@
meteor-platform meteor-platform
autopublish autopublish
insecure insecure
bootstrap twbs:bootstrap
nimble:restivus
iron:router
perak:codemirror
meteorhacks:npm
npm-container

View File

@@ -5,9 +5,9 @@ binary-heap@1.0.3
blaze@2.1.2 blaze@2.1.2
blaze-tools@1.0.3 blaze-tools@1.0.3
boilerplate-generator@1.0.3 boilerplate-generator@1.0.3
bootstrap@1.0.1
callback-hook@1.0.3 callback-hook@1.0.3
check@1.0.5 check@1.0.5
coffeescript@1.0.6
ddp@1.1.0 ddp@1.1.0
deps@1.0.7 deps@1.0.7
ejson@1.0.6 ejson@1.0.6
@@ -18,6 +18,14 @@ htmljs@1.0.4
http@1.1.0 http@1.1.0
id-map@1.0.3 id-map@1.0.3
insecure@1.0.3 insecure@1.0.3
iron:controller@1.0.7
iron:core@1.0.7
iron:dynamic-template@1.0.7
iron:layout@1.0.7
iron:location@1.0.7
iron:middleware-stack@1.0.7
iron:router@1.0.7
iron:url@1.0.7
jquery@1.11.3_2 jquery@1.11.3_2
json@1.0.3 json@1.0.3
launch-screen@1.0.2 launch-screen@1.0.2
@@ -25,12 +33,17 @@ livedata@1.0.13
logging@1.0.7 logging@1.0.7
meteor@1.1.6 meteor@1.1.6
meteor-platform@1.2.2 meteor-platform@1.2.2
meteorhacks:async@1.0.0
meteorhacks:npm@1.3.0
minifiers@1.1.5 minifiers@1.1.5
minimongo@1.0.8 minimongo@1.0.8
mobile-status-bar@1.0.3 mobile-status-bar@1.0.3
mongo@1.1.0 mongo@1.1.0
nimble:restivus@0.6.6
npm-container@1.0.0
observe-sequence@1.0.6 observe-sequence@1.0.6
ordered-dict@1.0.3 ordered-dict@1.0.3
perak:codemirror@1.2.3
random@1.0.3 random@1.0.3
reactive-dict@1.1.0 reactive-dict@1.1.0
reactive-var@1.0.5 reactive-var@1.0.5
@@ -42,6 +55,7 @@ spacebars@1.0.6
spacebars-compiler@1.0.6 spacebars-compiler@1.0.6
templating@1.1.1 templating@1.1.1
tracker@1.0.7 tracker@1.0.7
twbs:bootstrap@3.3.4
ui@1.0.6 ui@1.0.6
underscore@1.0.3 underscore@1.0.3
url@1.0.4 url@1.0.4

View File

@@ -0,0 +1,8 @@
<head>
<title>confighub</title>
</head>
<body>
</body>

79
web/client/confighub.js Normal file
View File

@@ -0,0 +1,79 @@
// pages
// / => home
// /:machineName => machineDetails
// .
Machines = new Mongo.Collection("machines");
Router.route('/', function() {
this.render('Home')
});
Router.route('machine/:machineId', function() {
this.render('machinePage', {
data: function() {
return Machines.findOne({
machineId: this.params.machineId
});
}
});
});
Router.route('/machine/:machineId/config/:configId', function() {
this.render('configPage', {
data: function() {
var config = Machines.find({
"machineId": this.params.machineId,
"configurations._id": this.params.configId
}, {
'configurations.$': 1
});
var machine = Machines.findOne({machineId: this.params.machineId});
return {
machine: machine,
config: config
};
// return config;
}
});
});
// this.render('Post', {
// // we don't really need this since we set the data context for the
// // the entire layout above. But this demonstrates how you can set
// // a new data context for each specific region.
// data: function () { return Posts.findOne({_id: this.params._id})
// });
if (Meteor.isServer) {
Meteor.startup(function() {
// code to run on server at startup
// Global API configuration
Restivus.configure({
prettyJson: true
});
Restivus.addRoute('machines', {
authRequired: false
}, {
get: function() {
var allMaMachines = Machines.find({});
return {
data: allMaMachines
};
// var post = Posts.findOne(this.urlParams.id);
// if (post) {
// return {status: 'success', data: post};
// }
// return {
// statusCode: 404,
// body: {status: 'fail', message: 'Post not found'}
// };
}
});
});
}

View File

@@ -0,0 +1,22 @@
<template name='configPage'>
<div class='container'>
<div class='row'>
<h1>confighub.io</h1>
<div class='col-lg-12'>
<h2>
Configuration page for {{ machine.machineId}} {{ config.type }} {{ config.description }}
</h2>
</div>
</div>
<div class="row">
<div class="col-lg-12">
{{> CodeMirror id="config-content" name="config-content" options=editorOptions code=editorCode reactiveVar="varName"}}
</div>
</div>
<div class="row">
<button class="save-config-details-btn">Save</button>
</div>
</div>
</template>

View File

@@ -0,0 +1,5 @@
Template.configPage.events({
"click .save-config-details-btn": function(event, template) {
console.log('should save config!!!');
}
})

View File

@@ -0,0 +1,21 @@
<template name='home'>
<div class='container'>
<div class='row'>
<h1>confighub.io</h1>
<div class='col-lg-12'>
<h2>
Your machines
</h2>
</div>
</div>
{{> machineList machines=machines}}
{{#unless newMachineRequested}}
<div class="row">
<div class='col-lg-12'>
<button type='button' class='add-new-machine-btn'>Add new machine</button>
</div>
</div>
{{/unless}} {{#if newMachineRequested}} {{> newMachine }} {{/if}}
</div>
</template>

View File

@@ -0,0 +1,85 @@
// var Machines = new Mongo.Collection("machines");
function guid() {
function s4() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
}
return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
s4() + '-' + s4() + s4() + s4();
}
// counter starts at 0
// Session.setDefault('counter', 0);
Template.home.helpers({
machines: function() {
return Machines.find({});
},
newMachineRequested: function() {
return Session.get('newMachineRequested');
}
});
Template.home.events({
"click .add-new-machine-btn": function() {
Session.set('newMachineRequested', true);
}
});
// Template.hello.helpers({
// counter: function() {
// return Session.get('counter');
// }
// });
// Template.hello.events({
// 'click button': function() {
// // increment the counter when button is clicked
// Session.set('counter', Session.get('counter') + 1);
// }
// });
Template.newMachine.helpers({
// because the Session variable will most probably
// be undefined the first time
// return true;
newMachineAdded: function() {
return Session.get("newMachineJustAdded");
}
});
Template.newMachine.events({
"click .close-new-machine-btn": function() {
Session.set('newMachineJustAdded', false);
Session.set('newMachineRequested', false);
},
"submit .new-machine": function(event) {
event.preventDefault();
return false;
},
"click .new-machine-save-btn": function(event, template) {
// This function is called when the new task form is submitted
// console.log('saving!!!!!!');
// event.preventDefault();
// return false;
//
var text = template.find('.machine-name').value; //vent.target.machineName.value;
var machineId = guid();
Machines.insert({
name: text,
status: 'init pending',
configurations: [],
machineId: machineId,
createdAt: new Date() // current time
});
// Clear form
template.find('.machine-name').value = "";
Session.set('newMachineJustAdded', machineId);
// Prevent default form submit
return false;
}
});

View File

@@ -0,0 +1,27 @@
<template name='machinePage'>
<div class='container'>
<div class='row'>
<h1>confighub.io</h1>
<div class='col-lg-12'>
<h2>
Machine details: {{ name }}
</h2>
</div>
</div>
<div class="row">
<div class="col-lg-12">
Machine status: {{status}}
</div>
</div>
<div class="row">
<div class="col-lg-12">
<h3>Configurations</h3>
{{> configurationList configurations=configurations machineId=machineId}}
</div>
</div>
</div>
</template>

View File

@@ -0,0 +1,20 @@
<template name='configurationList'>
<div class="row">
{{#each configurations}}
{{> configurationListItem}}
{{else}}
You don't have any configurations for this machine.
{{/each}}
</div>
{{#unless newConfigurationRequested}}
<div class="row">
<div class="col-lg-12">
<button class='add-new-config-btn'>Add new configuration</button>
</div>
</div>
{{/unless}}
{{#if newConfigurationRequested}}
{{> newConfigurationDialog machineId=machineId}}
{{/if}}
</template>

View File

@@ -0,0 +1,12 @@
Template.configurationList.events({
"click .add-new-config-btn": function(event, template) {
console.log('should add new configuration');
Session.set('newConfigurationRequested', true);
}
});
Template.configurationList.helpers({
newConfigurationRequested: function() {
return Session.get('newConfigurationRequested');
}
});

View File

@@ -0,0 +1,13 @@
<template name='configurationListItem'>
<div class="col-lg-4" style='text-align: center'>
<a href=/machine/{{machineId}}/config/{{_id}}>
<img src="http://gopherwarestudios.com/wp-content/uploads/2015/05/apache-icon.gif" alt="">
<div>
{{ type }}
</div>
<div>
{{ description }}
</div>
</a>
</div>
</template>

View File

@@ -0,0 +1,15 @@
<template name="machineDetails">
<div class="col-lg-4" style="text-align: center;">
<a href=machine/{{ machineId }}>
<img src='https://d13yacurqjgara.cloudfront.net/users/595800/screenshots/1702094/linux_1x.png' style="width: 200px; 130px;" />
<br />
<div style="text-align: center;" class="machine-name">
{{name}}
</div>
</a>
<div style="text-align: center;" class="machine-status">
status: {{status}}
</div>
</div>
</template>

View File

@@ -0,0 +1,5 @@
<template name='machineList'>
<div class="row">
{{#each machines}} {{> machineDetails}} {{/each}}
</div>
</template>

View File

@@ -0,0 +1,29 @@
<template name='newConfigurationDialog'>
<div class="row">
<div class="col-lg-3">
Configuration type
</div>
<div class="col-lg-3">
<select name="configurationTypes" class='config-type'>
<option value="apache">Apache</option>
<option value="nginx">Nginx</option>
<option value="elasticsearch">Elasticsearch</option>
<option value="unicorn">Unicorn</option>
<option value="passenger">Passenger</option>
<option value="hosts">HOSTS file</option>
</select>
</div>
<div class="colg-lg-3">
<input type="text" class='configuration-description form-control' placeholder="Description" />
</div>
<div class="col-lg-3">
<button class="save-config-btn">Save</button>
<button class="cancel-save-config-btn">Cancel</button>
</div>
</div>
</template>

View File

@@ -0,0 +1,36 @@
Template.newConfigurationDialog.events({
"click .save-config-btn": function(event, template) {
// console.log(template.data.machineId);
// var text = template.find('.machine-name').value; //vent.target.machineName.value;
var machine = Machines.findOne({
machineId: template.data.machineId
});
var configDescription = template.find('.configuration-description').value;
var configType = template.find('.config-type').value;
if (machine) {
Machines.update({
_id: machine._id
}, {
$push: {
configurations: {
machineId: machine.machineId,
_id: (new Mongo.ObjectID()).toHexString(),
description: configDescription,
type: configType
}
}
});
// db.students.update(
// { _id: 1 },
// { $push: { scores: 89 } }
// )
}
Session.set('newConfigurationRequested', false);
},
"click .cancel-save-config-btn": function(event, template) {
Session.set('newConfigurationRequested', false);
}
});

View File

@@ -0,0 +1,16 @@
<template name="newMachine">
<div class="row">
<div class="col-lg-12">
<h3>Add new machine</h3>
<form class="new-machine">
<input type="text" name="machineName" class='machine-name' placeholder="Machine Name" />
<button type='button' name='btnAddNewMachine' class='new-machine-save-btn'>Add new machine</button>
{{#if newMachineAdded}}
<div>You have successfully added a new machine. Please run <b>'chub init {{newMachineAdded}}'</b> on your computer. </div>
<button type='button' class='close-new-machine-btn'>Ok! Got It.</button>
{{/if}}
</form>
</div>
</div>
</template>

View File

@@ -1,30 +0,0 @@
<head>
<title>confighub</title>
</head>
<body>
<div class="container">
<div class="row">
<h1>Welcome to confighub.io</h1>
<div class="col-lg-12">
Here goes list of machines
</div>
</div>
<div class="row">
{{#each machines}}
{{> machineDetails}}
{{/each}}
</div>
</div>
<!-- {{> hello}} -->
</body>
<template name="machineDetails">
<div class="col-lg-4">{{hostname}}</div>
</template>
<template name="hello">
<button>Click Me</button>
<p>You've pressed the button {{counter}} times.</p>
</template>

View File

@@ -1,32 +0,0 @@
var Machines = new Mongo.Collection("machines");
if (Meteor.isClient) {
// counter starts at 0
Session.setDefault('counter', 0);
Template.body.helpers({
machines: function() {
return [{hostname: 'machine1'}, {hostname:' machine2'}];
return Machines.find({});
}
});
Template.hello.helpers({
counter: function () {
return Session.get('counter');
}
});
Template.hello.events({
'click button': function () {
// increment the counter when button is clicked
Session.set('counter', Session.get('counter') + 1);
}
});
}
if (Meteor.isServer) {
Meteor.startup(function () {
// code to run on server at startup
});
}

3
web/packages.json Normal file
View File

@@ -0,0 +1,3 @@
{
}

View File

@@ -0,0 +1,9 @@
Meteor.npmRequire = function(moduleName) {
var module = Npm.require(moduleName);
return module;
};
Meteor.require = function(moduleName) {
console.warn('Meteor.require is deprecated. Please use Meteor.npmRequire instead!');
return Meteor.npmRequire(moduleName);
};

View File

@@ -0,0 +1,23 @@
var path = Npm.require('path');
var fs = Npm.require('fs');
Package.describe({
summary: 'Contains all your npm dependencies',
version: '1.0.0',
name: 'npm-container'
});
var packagesJsonFile = path.resolve('./packages.json');
try {
var fileContent = fs.readFileSync(packagesJsonFile);
var packages = JSON.parse(fileContent.toString());
Npm.depends(packages);
} catch (ex) {
console.error('ERROR: packages.json parsing error [ ' + ex.message + ' ]');
}
// Adding the app's packages.json as a used file for this package will get
// Meteor to watch it and reload this package when it changes
Package.onUse(function(api) {
api.add_files(['index.js', '../../packages.json'], 'server');
});

View File

@@ -0,0 +1,70 @@
user www www; ## Default: nobody
worker_processes 5; ## Default: 1
error_log logs/error.log;
pid logs/nginx.pid;
worker_rlimit_nofile 8192;
events {
worker_connections 4096; ## Default: 1024
}
http {
include conf/mime.types;
include /etc/nginx/proxy.conf;
include /etc/nginx/fastcgi.conf;
index index.html index.htm index.php;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] $status '
'"$request" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log logs/access.log main;
sendfile on;
tcp_nopush on;
server_names_hash_bucket_size 128; # this seems to be required for some vhosts
server { # php/fastcgi
listen 80;
server_name domain1.com www.domain1.com;
access_log logs/domain1.access.log main;
root html;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:1025;
}
}
server { # simple reverse-proxy
listen 80;
server_name domain2.com www.domain2.com;
access_log logs/domain2.access.log main;
# serve static files
location ~ ^/(images|javascript|js|css|flash|media|static)/ {
root /var/www/virtual/big.server.com/htdocs;
expires 30d;
}
# pass requests for dynamic content to rails/turbogears/zope, et al
location / {
proxy_pass http://127.0.0.1:8080;
}
}
upstream big_server_com {
server 127.0.0.3:8000 weight=5;
server 127.0.0.3:8001 weight=5;
server 192.168.0.1:8000;
server 192.168.0.1:8001;
}
server { # simple load balancing
listen 80;
server_name big.server.com;
access_log logs/big.server.access.log main;
location / {
proxy_pass http://big_server_com;
}
}
}

62
web/server/confighub.js Normal file
View File

@@ -0,0 +1,62 @@
Machines = new Mongo.Collection("machines");
Meteor.startup(function() {
// code to run on server at startup
// Global API configuration
Restivus.configure({
prettyJson: true,
useAuth: false
});
Restivus.addCollection(Machines);
Restivus.addRoute('post/:_id', {
get: function () {
var id = this.urlParams._id; // "5"
return {hamo:1}
}
});
Restivus.addRoute('/api/templates/:type', {
},{
get: {
action: function() {
var type = this.urlParams.type;
var fs = Meteor.npmRequire('fs');
var template = Async.runSync(function(done) {
// github.gists.getFromUser({user: 'arunoda'}, function(err, data) {
// done(null, data);
// });
fs.readFile('../public/configs/'+type+'.conf', function(err, data) {
done(null, data);
});
});
return template.result;
}
}
})
// Restivus.addRoute('/api/machines', {
// // authRequired: false
// }, {
// get: {
// action: function() {
// var allMaMachines = Machines.find({});
// return {
// meho:1,
// data: allMaMachines
// };
// }
// // var post = Posts.findOne(this.urlParams.id);
// // if (post) {
// // return {status: 'success', data: post};
// // }
// // return {
// // statusCode: 404,
// // body: {status: 'fail', message: 'Post not found'}
// // };
// }
// });
});