diff --git a/lib/requests/controllers/recording_prompt.controller.js b/lib/requests/controllers/recording_prompt.controller.js index 151787f..de62761 100644 --- a/lib/requests/controllers/recording_prompt.controller.js +++ b/lib/requests/controllers/recording_prompt.controller.js @@ -37,12 +37,12 @@ module.exports = function(app, _parent) { $scope.startRecording = function() { $scope.COUNTDOWN = true; - + $scope.TEXTMODE = false; + $scope.textRequestDescription = ""; var sc = angular.element(document.querySelector('#recordingSpan')).scope(); $timeout(function(){ sc.$apply(function(){ sc.uploading = false; - }) },0,false).then(function(){ $timeout(function(){ @@ -51,9 +51,30 @@ module.exports = function(app, _parent) { }) }; - $scope.cancelPrompt = function() { + // triggers text request box + $scope.textRecording = function() { + //hide h2, hide start recording button + $scope.TEXTMODE = true + $scope.textRequestDescription = "" + }; + + // submit text request + $scope.textRequestSubmittion = function (){ + + _parent.sendingTextDesc($scope.requestTitle,$scope.textRequestDescription); + //re-configure + $scope.requestTitle = ""; + $scope.textRequestDescription = "" + $scope.TEXTMODE = false; + $scope.COUNTDOWN = false; + _parent.closePrompt(); + } + // cancels codeon request title prompt + $scope.cancelPrompt = function() { $scope.requestTitle = ""; + $scope.textRequestDescription = "" + $scope.TEXTMODE = false $scope.COUNTDOWN = false; var scope = angular.element(document.querySelector('#makeRequest')).scope(); $timeout(function(){ @@ -65,5 +86,7 @@ module.exports = function(app, _parent) { _parent.closePrompt(); }); }; + + }]); }; diff --git a/lib/requests/requestView.js b/lib/requests/requestView.js index f8cdb2b..95c2f7f 100644 --- a/lib/requests/requestView.js +++ b/lib/requests/requestView.js @@ -4,6 +4,7 @@ var $ = require('jquery'), pfs = require('../utils/promised_fs'), path = require('path'); + module.exports = RequestView; function RequestView() { @@ -27,6 +28,7 @@ function RequestView() { require('./services/record_files')(this.app); require('./services/record_voice')(this.app); require('./services/upload_recording')(this.app); + require('./services/upload_textrequest')(this.app); require('./services/recorder')(this.app); require('./controllers/recording_bar.controller')(this.app); require('./controllers/recording_prompt.controller')(this.app, this); @@ -74,7 +76,7 @@ function RequestView() { return Recorder.isRecording(); }); }; - + // enable editor + voice recording proto.enable = function(title) { if (!this.isRecording()) { @@ -84,6 +86,15 @@ function RequestView() { this.panel.show(); } }; + + // send the title and the text description + proto.sendingTextDesc = function(title, request){ + // console.log(title, request); + this._invoke(function(Recorder) { + Recorder.sendingTextRequest(title, request); + }); + }; + proto.disable = function() { if (this.isRecording()) { @@ -134,6 +145,7 @@ function RequestView() { }); this.panel.destroy(); }; + // send the title of the request proto.toggle = function(title) { if (this.isRecording()) { this.disable(); @@ -141,4 +153,9 @@ function RequestView() { this.enable(title); } }; + + + + + }(RequestView)); diff --git a/lib/requests/services/record_voice.js b/lib/requests/services/record_voice.js index 3fa5723..0b71fc5 100644 --- a/lib/requests/services/record_voice.js +++ b/lib/requests/services/record_voice.js @@ -10,7 +10,6 @@ recognitionEngine.interimResults = false; recognitionEngine.maxResults = 1; - function getUserMedia() { return new Promise(function(resolve, reject) { diff --git a/lib/requests/services/recorder.js b/lib/requests/services/recorder.js index 0f2204e..c5ce994 100644 --- a/lib/requests/services/recorder.js +++ b/lib/requests/services/recorder.js @@ -2,8 +2,8 @@ var guid = require('../../utils/guid'); module.exports = function(app) { var uid, cwd, requestTitle; return app.factory('Recorder', ['$rootScope', 'EditorRecorder', - 'FileRecorder', 'VoiceRecorder', 'UploadRecording', - function($rootScope, EditorRecorder, FileRecorder, VoiceRecorder, UploadRecording) { + 'FileRecorder', 'VoiceRecorder', 'UploadRecording', 'UploadTextRequest', + function($rootScope, EditorRecorder, FileRecorder, VoiceRecorder, UploadRecording, UploadTextRequest) { console.log("recorder.js"); var recorder = { recording: false, @@ -61,6 +61,11 @@ module.exports = function(app) { UploadRecording(uid, EditorRecorder, VoiceRecorder, FileRecorder, cwd, requestTitle); } }, + sendingTextRequest: function(title, request){ + uid = guid(); + cwd = FileRecorder.start(uid); + UploadTextRequest(uid, cwd, title, request,FileRecorder); + }, cancel: function() { if (this.isRecording()) { diff --git a/lib/requests/services/upload_textrequest.js b/lib/requests/services/upload_textrequest.js new file mode 100644 index 0000000..a979864 --- /dev/null +++ b/lib/requests/services/upload_textrequest.js @@ -0,0 +1,193 @@ +var prefs = require('../../utils/user_preferences'); +var pfs = require('../../utils/promised_fs'); +var fs = require('fs'); +var path = require('path'); +var FormData = require('form-data'); +var _ = require('underscore') + +module.exports = function(app){ + app.factory('UploadTextRequest', ['STORAGE_DIRECTORY','EditorRecorder','Slack', function(STORAGE_DIRECTORY, EditorRecorder, Slack){ + return function(uid, cwd, title, request, workspaceSnapshot){ + console.log(uid, cwd, title,request); + var folder = path.join(STORAGE_DIRECTORY, uid); + var filename = 'recording.json', + fullFilename = path.join(folder, filename); + EditorRecorder.start(uid, cwd); + EditorRecorder.stop(uid).then(function(info){ + var recordingInfo = { + title: title, + request_description: request, + question_id: uid, + editor_id: prefs.getEditorID(), + transcript: "worked", + changelog: info, + cwd: cwd + }; + + return pfs.mkdirp(folder).then(function() { + debugger; + return pfs.writeJson(fullFilename, recordingInfo).then(function() { + return workspaceSnapshot.addFile(fullFilename, filename); + }); + }); + }).then(function(){ + return workspaceSnapshot.stop(uid); + }).then(function(zipFilename){ + return pfs.remove(folder).then(function() { + return zipFilename; + }); + }).then(function(zipFilename){ + var form = new FormData(); + form.append('recording', fs.createReadStream(zipFilename)); + return new Promise(function(resolve, reject) { + form.submit(prefs.getUploadURL(), function(err, result) { + if (err) { + reject(err); + } else { + resolve(zipFilename); + } + }); + }); + }).then(function(zipFilename) { + return pfs.remove(zipFilename); + }).then(function() { + if (prefs.postRequestsToSlack()) { + return Slack.postRequest(uid, requestTitle); + } else { + return; + } + }).then(function() { + console.log("Uploaded to " + prefs.getUploadURL()); + }, function(err) { + console.error(err.stack); + }); + } + }]); +} + + + + + + + + +// +// +// +// +// +// +// +// +// var pfs = require('../../utils/promised_fs'); +// var prefs = require('../../utils/user_preferences'); +// //var angular = require('angular'); +// var fs = require('fs'); +// var path = require('path'); +// var FormData = require('form-data'); +// var _ = require('underscore') +// +// module.exports = function(app) { +// var changelog; +// app.factory('UploadTextRequest', ['$q', '$rootScope', 'STORAGE_DIRECTORY', 'Slack', function($q, $rootScope, STORAGE_DIRECTORY, Slack) { +// return function(uid, editorRecorder, voiceRecorder, workspaceSnapshot, cwd, requestTitle) { +// var changelogPromise = editorRecorder.stop(uid); +// var promises = voiceRecorder.stop(uid), +// wavPromise = promises; +// +// var wavFilePromise = wavPromise.then(function(wavFilename) { +// console.log("wavPromise : " + wavFilename); +// workspaceSnapshot.addFile(wavFilename, path.basename(wavFilename)); +// }); +// var folder = path.join(STORAGE_DIRECTORY, uid); +// var skype = prefs.getContact(); +// if (requestTitle == null) { +// requestTitle = 'This person is too lazy to leave anything ...' +// } +// changelogPromise.then(function(info) { +// +// var changelog = info; +// var recordingInfo = { +// contact: skype, +// title: requestTitle, +// question_id: uid, +// editor_id: prefs.getEditorID(), +// transcript: "worked", +// changelog: changelog, +// cwd: cwd +// }; +// +// //add gutter icon to indicate the location, which should be the same as showlocation +// var editor = atom.workspace.getActiveTextEditor(); +// debugger; +// _.every(changelog, function(obj) { +// if (obj.type == 'cursor') { +// editor.scrollToScreenPosition(obj.cursor, { +// center: true +// }); +// editor.setCursorScreenPosition(obj.cursor); +// return false; +// } +// +// if (obj.type == 'selection_range') { +// editor.scrollToScreenPosition(obj.range[0], { +// center: true +// }); +// editor.setCursorScreenPosition(obj.range[0]); +// return false; +// } +// +// return true; +// }); +// +// var filename = 'recording.json', +// fullFilename = path.join(folder, filename); +// +// return pfs.mkdirp(folder).then(function() { +// debugger; +// return pfs.writeJson(fullFilename, recordingInfo).then(function() { +// return workspaceSnapshot.addFile(fullFilename, filename); +// }); +// }); +// }); +// +// return Promise.all([wavFilePromise, changelogPromise]).then(function() { +// console.log("transcript(wavFilePromise, infoPromise) : "); +// +// return workspaceSnapshot.stop(uid); +// }).then(function(zipFilename) { +// console.log("transcript(wavFilePromise, infoPromise)2 : "); +// +// return pfs.remove(folder).then(function() { +// return zipFilename; +// }); +// }).then(function(zipFilename) { +// console.log("Wrote to " + zipFilename); +// var form = new FormData(); +// form.append('recording', fs.createReadStream(zipFilename)); +// return new Promise(function(resolve, reject) { +// form.submit(prefs.getUploadURL(), function(err, result) { +// if (err) { +// reject(err); +// } else { +// resolve(zipFilename); +// } +// }); +// }); +// }).then(function(zipFilename) { +// return pfs.remove(zipFilename); +// }).then(function() { +// if (prefs.postRequestsToSlack()) { +// return Slack.postRequest(uid, requestTitle); +// } else { +// return; +// } +// }).then(function() { +// console.log("Uploaded to " + prefs.getUploadURL()); +// }, function(err) { +// console.error(err.stack); +// }); +// }; +// }]); +// }; diff --git a/lib/requests/views/recording_prompt.view.html b/lib/requests/views/recording_prompt.view.html index 158f28e..fec6315 100644 --- a/lib/requests/views/recording_prompt.view.html +++ b/lib/requests/views/recording_prompt.view.html @@ -2,10 +2,21 @@
diff --git a/lib/response/views/response_panel.view.html b/lib/response/views/response_panel.view.html index fb06506..515a156 100644 --- a/lib/response/views/response_panel.view.html +++ b/lib/response/views/response_panel.view.html @@ -1,350 +1,297 @@