From b8dd79c2d6c5bc9ed16bd236ae9b2a36e0d7017a Mon Sep 17 00:00:00 2001 From: Phacometer Date: Sun, 4 Dec 2016 10:42:00 -0400 Subject: [PATCH 1/5] Fix spelling errors in OBJloader.js From a36e1717114b5b0a381e075804942c542decde15 Mon Sep 17 00:00:00 2001 From: Phacometer Date: Sun, 4 Dec 2016 10:50:22 -0400 Subject: [PATCH 2/5] Fix spelling errors --- OGV/client/lib/OrbitControls.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/OGV/client/lib/OrbitControls.js b/OGV/client/lib/OrbitControls.js index 8d4ed683..8957228e 100644 --- a/OGV/client/lib/OrbitControls.js +++ b/OGV/client/lib/OrbitControls.js @@ -44,8 +44,8 @@ THREE.OrbitControls = function ( object, domElement ) { this.zoomSpeed = 1.0; // Limits to how far you can dolly in and out - this.minDistance = 0; - this.maxDistance = Infinity; + this.minDistance = 20; + this.maxDistance = 10000; // Set to true to disable this control this.noRotate = false; @@ -257,7 +257,7 @@ THREE.OrbitControls = function ( object, domElement ) { // restrict phi to be between desired limits phi = Math.max( this.minPolarAngle, Math.min( this.maxPolarAngle, phi ) ); - // restrict phi to be betwee EPS and PI-EPS + // restrict phi to be between EPS and PI-EPS phi = Math.max( EPS, Math.min( Math.PI - EPS, phi ) ); var radius = offset.length() * scale; From 55a4036bc320172157195a3b7cacbb1e05b41a5c Mon Sep 17 00:00:00 2001 From: Phacometer Date: Sun, 4 Dec 2016 10:53:22 -0400 Subject: [PATCH 3/5] Fix spelling errors --- OGV/client/views/model_meta.js | 106 ++++++++++++++++++++++++++------- OGV/client/views/social.js | 38 +++++++++--- 2 files changed, 112 insertions(+), 32 deletions(-) diff --git a/OGV/client/views/model_meta.js b/OGV/client/views/model_meta.js index a1f31056..f7c3a37c 100644 --- a/OGV/client/views/model_meta.js +++ b/OGV/client/views/model_meta.js @@ -1,4 +1,4 @@ -/* M O D E L _ M E T A . J S +/** M O D E L _ M E T A . J S * BRL-CAD * * Copyright (c) 1995-2013 United States Government as represented by @@ -36,32 +36,92 @@ Template.modelMeta.events({ 'submit #uploader-form': function(e, t) { e.preventDefault(); - + a = e; var modelMetaForm = $(e.currentTarget), filename = modelMetaForm.find('#desc-filename').val().toLowerCase(), description = modelMetaForm.find('#desc-about').val(), - thumbnail, - modelId = modelMetaForm.find('#model-id').val(); + modelId = modelMetaForm.find('#model-id').val(), + audience = modelMetaForm.find('#desc-audience').val(), + currentUser = Meteor.user(); - file = $('#desc-model-thumb') - - var fsFile = new FS.File(e.target[2].files[0]); - fsFile.gFile = modelId; - - ThumbFiles.insert(fsFile,function(err,thumbFile) { - if (err) { - throwError(err.reason); + /** + * Adding the checked boxes to an array named category + */ + var category = Array(); + $("input:checkbox[name=category]:checked").each(function(){ + category.push($(this).val()); + }); + + var currentModel = ModelFiles.findOne(modelId); + + ModelFiles.update(modelId, {$set: {name: filename, about: description, audience: audience}}, function(error, res) { + if (error) { + sAlert.error(error.reason); } else { - throwNotification("Image has been Uploaded" ); - ModelFiles.update(modelId, {$set: {name: filename, about: description, thumbnail:thumbFile._id}}, function(error, res) { - if (error) { - throwError(error.reason); - } else { - throwNotification("Data about model has been saved"); - } - }); - + sAlert.success("Data about model has been saved"); } - }); - } + }); + Posts.insert({ + postType: "posted", + postedAt: currentModel.timeUploaded, + postId: modelId, + postedBy: currentUser._id, + audience: audience + }); + if(category.length > 0){ + ModelFiles.update(modelId, {$set: {categories: category}}, function(error, res) { + if (error) { + sAlert.error(error.reason); + } else { + sAlert.success("Data about model has been saved"); + } + }); + } + /*cPercent = Meteor.call('convertPercent'); + console.log("######"); + console.log(cPercent); + console.log("######");*/ + + var uploadedModel = ModelFiles.findOne(modelId); + if( uploadedModel.converted ){ + Router.go('/models/'+uploadedModel._id); + sAlert.success("Data about model has been saved"); + } else { + ModelFiles.remove(uploadedModel._id); + Router.go('/upload'); + sAlert.success("There was some error in converting your uploaded file"); + } + + + +} +}); + +Template.modelMeta.helpers({ + 'progressValue': function(){ + var id = $('#model-id').val(), + modelObj = ModelFiles.findOne({_id: id}); + var value = modelObj.conversion; + value = parseInt(value, 10); + if(value == null) value = 0; + if(value >= 70) { + $('progress[value]').css('display', 'none'); + $('.progress-label').css('display', 'none'); + $('#save-btn').css('display', 'block'); + return value; + } else { + return value; + } + } }); + +/** +* helper to display already present categories in the model +* Displayed every time when the /description/:_id page is viewed +* Displays nothing if categories is empty. +*/ +Template.modelMeta.modelCategory = function() +{ + var id = Session.get('modelId'); + return ModelFiles.findOne({_id: id}); +}; diff --git a/OGV/client/views/social.js b/OGV/client/views/social.js index 44265d37..69397bc6 100644 --- a/OGV/client/views/social.js +++ b/OGV/client/views/social.js @@ -1,3 +1,6 @@ +/** +* Comments and its backend implementation +*/ Template.comment.helpers({ submittedText: function() { return new Date(this.submitted).toString(); @@ -9,18 +12,27 @@ Template.commentSubmit.events({ 'submit form': function(e, template) { e.preventDefault(); var $body = $(e.target).find('[name=body]'); + if(this.converted){ + postId = this._id; + } else { + postId = this.postId; + } var comment = { body: $body.val(), - postId: this._id + postId: postId }; Meteor.call('comment', comment, function(error, commentId) { if (error){ - throwError(error.reason); + sAlert.error(error.reason); } else { $body.val(''); + var commentOnModel = Comments.findOne(commentId); + ModelFiles.update(commentOnModel.postId, {$inc: {commentsCount: 1}}); } + }); + } }); @@ -28,7 +40,7 @@ Template.commentSubmit.events({ Template.commentBody.helpers({ comments: function() { - var commentList = Comments.find({postId:this._id}); + var commentList = Comments.find({postId:this.postId}); if (!commentList) commentList = Comments.find({postId:this.data._id}); return commentList } @@ -50,23 +62,31 @@ Template.comments.events({ } }); - + +/** +* Likes and its backend implementation +*/ Template.lovemeter.events({ 'click .lovemeter-wrapper':function(){ var love = { - postId: this._id + postId: this.postId }; - Meteor.call('love', love, function(error, loveId) { + Meteor.call('love', love, function(error, loveId) { if (error){ - throwError(error.reason); + sAlert.error(error.reason); } - }); + }); } }); Template.lovemeter.helpers({ lovers: function(){ - loversObj = Lovers.findOne({postId: this._id}); + if(this.postId){ + id = this.postId; + } else { + id = this._id; + } + loversObj = Lovers.findOne({postId: id}); if(loversObj){ loversArray = loversObj.lovers; return loversArray.length; From bb46bb2a124d30bed8a3ce96b4f151b6279c6904 Mon Sep 17 00:00:00 2001 From: Phacometer Date: Sun, 4 Dec 2016 10:54:10 -0400 Subject: [PATCH 4/5] Fix spelling errors --- OGV/lib/router.js | 145 ++++++++++++++++++++++++++++++---------------- 1 file changed, 96 insertions(+), 49 deletions(-) diff --git a/OGV/lib/router.js b/OGV/lib/router.js index 29dc7709..cc82be5e 100644 --- a/OGV/lib/router.js +++ b/OGV/lib/router.js @@ -33,58 +33,112 @@ Router.configure({ layoutTemplate:'layout', + notFoundTemplate: 'notFound', loadingTemplate:'preloader', - waitOn: function() { return Meteor.subscribe('modelFiles'); }, }); - /** * Mapping urls to template names */ + Router.map(function() { - this.route('index', { - path : '/' - }); + this.route('landingPage', { path : '/' }); this.route('signUp', {path : 'sign-up'}); + this.route('feedbackThanks', {path : 'thanks'}); this.route('logIn', {path : 'log-in'}); - this.route('cfsUploader', {path : 'upload'}); this.route('notVerified', {path : 'not-verified'}); this.route('forgotPassword', {path : 'forgot-password'}); - this.route('filemanager', {path : 'filemanager'}); + this.route('home', {path : 'home'}); + this.route('cfsUploader',{ + path: 'upload', + waitOn: function() { + return Meteor.subscribe('modelFiles'); + } + }); + this.route('dashboard',{ - path: 'dashboard', - waitOn: function() { - return Meteor.subscribe('ogvSettings'); - } + path: 'dashboard', + waitOn: function() { + return Meteor.subscribe('ogvSettings'); + } }); + this.route('modelViewer', { - path: '/models/:_id', - data: function() - { - return ModelFiles.findOne (this.params._id); - }, - action : function () { - if (this.ready()) this.render(); - } + path: '/models/:_id/:_share?', + waitOn: function() { + return Meteor.subscribe('modelFiles'); + }, + data: function() + { + return ModelFiles.findOne (this.params._id); + }, + action : function () + { + if (this.ready()) this.render(); + }, + onRun: function() + { + ModelFiles.update(this.params._id, {$inc: {viewsCount: 1}}); + this.next(); + } }); this.route('modelMeta', { - path: '/description/:_id', - data: function() - { - return ModelFiles.findOne(this.params._id); - } + path: '/description/:_id', + waitOn: function() { + return Meteor.subscribe('modelFiles'); + }, + data: function() + { + var model = ModelFiles.findOne({'owner' : Meteor.user()._id}); + if( model == null ){ + Router.go('/upload'); + return; + } else { + Session.set('modelId', this.params._id); + return ModelFiles.findOne(this.params._id); + } + } + }); + + this.route('profilePage', { + path: '/profile/:_id', + waitOn:function() + { + return [Meteor.subscribe("userProfile",this.params._id), + Meteor.subscribe('modelFiles')]; + + }, + data: function(){ + var id = this.params._id; + personVar = Meteor.users.findOne( { _id:id } ); + return { + person: personVar + } + } }); - this.route('filemanager',{ - path: '/my-models', - data: function() - { - return ModelFiles.find({'owner' : Meteor.user()}); - } + this.route('explore', { + path:'/explore', + waitOn:function(){ + Meteor.subscribe('modelFiles'); + } + }); + + this.route('models', { + path : '/newsfeed/:modelId?', + waitOn: function() { + Meteor.subscribe('modelFiles'); + } }); }); +// add the dataNotFound plugin, which is responsible for +// rendering the dataNotFound template if your RouteController +// data function returns a falsy value +Router.plugin("dataNotFound",{ + notFoundTemplate: "dataNotFound" +}); /** * Some routes are shown only when user has a valid email @@ -92,17 +146,12 @@ Router.map(function() { */ var validateUser = function(pause) { if (Meteor.user()) { - if (Meteor.user().emails[0].verified) { - this.render(); - } else { - this.render('notVerified'); - } + this.next(); } else if (Meteor.loggingIn()) { - this.render('preloader'); + this.render('preloader'); } else { - this.render('logIn'); + this.render('logIn'); } - pause(); } @@ -113,11 +162,10 @@ var validateUser = function(pause) { var actionReady = function(pause) { if (this.ready()) { - this.render(); + this.next(); } else { - this.render('preloader'); + this.render('preloader'); } - pause(); } /** @@ -126,19 +174,18 @@ var actionReady = function(pause) */ var loggingIn = function(pause) { if (Meteor.loggingIn()) { - this.render('preloader'); + this.render('preloader'); } else { - this.render(); + this.next(); } - pause(); } /** - * Remove notifactions and error messages that have been seen - * everytime a route is changed + * Remove notifications and error messages that have been seen + * every time a route is changed */ -Router.onBeforeAction(function() { clearNotifications(); }); -Router.onBeforeAction(validateUser,{only:['cfsUploader','filemanager','dashboard','modelMeta']}); -Router.onBeforeAction(actionReady, {only:['index', 'modelViewer']}); + +Router.onBeforeAction(validateUser,{only:['cfsUploader','filemanager','dashboard','modelMeta', 'newsfeedSidebar', 'models', 'modelFeed', 'explore', 'profilePage', 'index']}); +Router.onBeforeAction(actionReady, {only:['index', 'modelViewer', 'profilePage', 'explore', 'models', 'modelFeed']}); Router.onBeforeAction(loggingIn); From 38789955061ad4179ce0a37fcdfa5c016d600cbb Mon Sep 17 00:00:00 2001 From: Phacometer Date: Sun, 4 Dec 2016 10:54:46 -0400 Subject: [PATCH 5/5] Fix spelling errors --- OGV/server/accounts.js | 65 +++++++++++++++++++-- OGV/server/cfs_uploader.js | 113 +++++++++++++++++++------------------ OGV/server/fixtures.js | 6 +- 3 files changed, 121 insertions(+), 63 deletions(-) diff --git a/OGV/server/accounts.js b/OGV/server/accounts.js index e56305f5..4b8e11c3 100644 --- a/OGV/server/accounts.js +++ b/OGV/server/accounts.js @@ -27,14 +27,14 @@ * and use OGV. */ -Accounts.config({ - sendVerificationEmail: true -}); - /** * Create a test user without admin roles and a super user with * admin roles on a fresh install (when number of users is zero) */ +Accounts.config({ + sendVerificationEmail:true, + //forbidClientAccountCreation: false +}) if (Meteor.users.find().fetch().length === 0) { var users = [ @@ -50,7 +50,7 @@ if (Meteor.users.find().fetch().length === 0) { id = Accounts.createUser({ email: userData.email, password: "ogv123", - profile: { name: userData.name, bio: Bio, pic: false } + profile: { name: userData.name, bio: Bio } }); // email verification @@ -59,4 +59,57 @@ if (Meteor.users.find().fetch().length === 0) { Roles.addUsersToRoles(id, userData.roles); }); -} + +} + +Accounts.onCreateUser(function(options, user) { + var followingArray = []; + //followingArray[0] = user._id; + var adminUser = Meteor.users.findOne({'roles.0': "admin"}); + followingArray[0] = adminUser._id; + followingArray[1] = user._id; + + if (options.profile){ + options.profile.following = followingArray; + user.profile = options.profile; + } else { + console.log(options); + } + + return user; +}); + +/*Meteor.users.allow({ + update: function(userId, user, fields) + { + if (!fields.isEqualTo(['profile.following', 'profile.follower'])) { + return false; + } else { + return true; + } + } +}); +*/ + + +/** +* Need to allow the users to update only the followers array of other users +*/ +Meteor.users.allow({ + update: function(userId, user, fieldNames, modifier) + { + return true; + } +}); + +/** + * Intended to Delete/Remove users who have not verified their Emails in hrs hours + */ +var hrs = 1; +Meteor.setInterval(function() { + Meteor.users.find({'emails.0.verified': false}).forEach(function(user) { + //Do action with 'user' that has not verified email for 1 hour + Meteor.users.remove({_id: user._id}, true); + }); +}, (3600000 * hrs)); + diff --git a/OGV/server/cfs_uploader.js b/OGV/server/cfs_uploader.js index a464654a..48cca1ca 100644 --- a/OGV/server/cfs_uploader.js +++ b/OGV/server/cfs_uploader.js @@ -1,5 +1,5 @@ /* C F S _ U P L O A D E R . J S - * BRL-CAD +* BRL-CAD * * Copyright (c) 1995-2013 United States Government as represented by * the U.S. Army Research Laboratory. @@ -27,7 +27,7 @@ Meteor.methods({ /** - * Converts g into obj iles + * Converts g into obj files */ convertFile:function(fileId) { @@ -39,6 +39,7 @@ Meteor.methods({ var sys = Npm.require('sys'), fs = Npm.require('fs'), exec = Npm.require('child_process').exec; + var convertPercentage = 0; var modelObj = ModelFiles.findOne(fileId), readStream = modelObj.createReadStream('modelFiles'), @@ -49,63 +50,67 @@ Meteor.methods({ mgedPath = settings.mgedPath, g_objPath = settings.gobjPath, cmd = mgedPath + " -c " + filePath +" ls -a 2>&1", + filePathArray = filePath.split('-'); uploadDirPath = filePath.substring(0, filePath.lastIndexOf("/")); + + modelObj.update({$set: {conversion: convertPercentage}}); /** * exec() function executes system commands and Meteor.BindEnvironment binds it * meteor environment so that they can share each other's variables */ - child = exec(cmd, Meteor.bindEnvironment (function (error, stdout, stderr) { - /** - * the command in cmd returns a list of obj files which are then converted into - * array , which is hence traversed to store each OBJ file in database - */ - sys.print('stdout' + stdout); - objects = stdout.split(" "); - console.log(objects); - sys.print('stderr' + stderr); - - if (error != null) { - console.log('exec error: ' + error); - } else { - - for (i = 1; i < objects.length; i++) { - var counter = 0; - (function(i) { - objPath[i] = uploadDirPath + "/" + objects[i] + ".obj"; - cmd = g_objPath + " -n 10 -o " + objPath[i] + " " + filePath + " " + objects[i]; - console.log(cmd); - child = exec(cmd, Meteor.bindEnvironment (function (error, stdout, stderr) { - if (error) { - throw (new Meteor.Error("There's some error in converting file" + error)); + child = exec(cmd, Meteor.bindEnvironment (function (error, stdout, stderr) { + /** + * the command in cmd returns a list of obj files which are then converted into + * array , which is hence traversed to store each OBJ file in database + */ + sys.print('stdout' + stdout); + objects = stdout.split(" "); + console.log(objects); + sys.print('stderr' + stderr); + + if (error != null) { + console.log('exec error: ' + error); + } else { + for (i = 0; i < objects.length; i++) { + var counter = 0; + (function(i) { + objPath[i] = uploadDirPath + "/" + objects[i] + ".obj"; + cmd = g_objPath + " -n 10 -o " + objPath[i] + " " + filePath + " " + objects[i]; + console.log(cmd); + child = exec(cmd, Meteor.bindEnvironment (function (error, stdout, stderr) { + if (error) { + throw (new Meteor.Error("There's some error in converting file" + error)); + } else { + console.log("File has been converted" + objects[i] + i); + objFS = new FS.File(objPath[i]); + objFS.gFile = fileId; + objFS.show = true; + objFS.color = '#ffffff'; + OBJFiles.insert(objFS, function (err, objFile) { + if (err) { + console.log(err); } else { - console.log("File has been converted" + objects[i] + i); - objFS = new FS.File(objPath[i]); - objFS.gFile = fileId; - OBJFiles.insert(objFS, function (err, objFile) { - if (err) { - console.log(err); - } else { - counter = counter + 1; - var convertPercentage = (counter/(objects.length - 2)) *100; - console.log("done " + convertPercentage + " %"); - /** - * The acceptance rate for succesfull conversion is at least 70% - * Any model with conversion less than that is not said to be - * converted and is not shown across the website. - */ - if (convertPercentage > 70) { - modelObj.update({$set: {converted: true}}); - console.log(modelObj); - } - } - }); - } - })); - })(i); - } - - } - })); + counter = counter + 1; + convertPercentage = (counter/(objects.length - 2)) *100; + modelObj.update({$set: {conversion: convertPercentage}}); + console.log("done " + convertPercentage + " %"); + /** + * The acceptance rate for successful conversion is at least 70% + * Any model with conversion less than that is not said to be + * converted and is not shown across the website. + */ + if (convertPercentage > 70) { + modelObj.update({$set: {converted: true}}); + console.log(modelObj); + } + } + }); + } + })); + })(i); + } + } + })); } -}); +}); diff --git a/OGV/server/fixtures.js b/OGV/server/fixtures.js index e82f6445..55a739f5 100644 --- a/OGV/server/fixtures.js +++ b/OGV/server/fixtures.js @@ -19,7 +19,7 @@ */ /** - * This file contains inital settings that are entered into database + * This file contains initial settings that are entered into database * during the first installation of the software */ if (OgvSettings.find().count() === 0) @@ -28,7 +28,7 @@ if (OgvSettings.find().count() === 0) settingSwitch: true, siteName :"Online Geometry Viewer", mailUrl : "http://username:password@example.com", - gobjPath : "/usr/brlcad/dev-7.25.0/bin/g-obj", - mgedPath : "/usr/brlcad/dev-7.25.0/bin/mged" + gobjPath : "/usr/brlcad/dev-7.24.2/bin/g-obj", + mgedPath : "/usr/brlcad/dev-7.24.2/bin/mged" }); }