Skip to content

Commit

Permalink
enable text request
Browse files Browse the repository at this point in the history
  • Loading branch information
chensivan committed Feb 2, 2017
1 parent c1f4aaa commit 2d8b4ee
Show file tree
Hide file tree
Showing 7 changed files with 487 additions and 292 deletions.
29 changes: 26 additions & 3 deletions lib/requests/controllers/recording_prompt.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(){
Expand All @@ -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(){
Expand All @@ -65,5 +86,7 @@ module.exports = function(app, _parent) {
_parent.closePrompt();
});
};


}]);
};
19 changes: 18 additions & 1 deletion lib/requests/requestView.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var $ = require('jquery'),
pfs = require('../utils/promised_fs'),
path = require('path');


module.exports = RequestView;

function RequestView() {
Expand All @@ -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);
Expand Down Expand Up @@ -74,7 +76,7 @@ function RequestView() {
return Recorder.isRecording();
});
};

// enable editor + voice recording
proto.enable = function(title) {
if (!this.isRecording()) {

Expand All @@ -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()) {

Expand Down Expand Up @@ -134,11 +145,17 @@ function RequestView() {
});
this.panel.destroy();
};
// send the title of the request
proto.toggle = function(title) {
if (this.isRecording()) {
this.disable();
} else {
this.enable(title);
}
};





}(RequestView));
1 change: 0 additions & 1 deletion lib/requests/services/record_voice.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ recognitionEngine.interimResults = false;
recognitionEngine.maxResults = 1;



function getUserMedia() {

return new Promise(function(resolve, reject) {
Expand Down
9 changes: 7 additions & 2 deletions lib/requests/services/recorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()) {

Expand Down
193 changes: 193 additions & 0 deletions lib/requests/services/upload_textrequest.js
Original file line number Diff line number Diff line change
@@ -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);
// });
// };
// }]);
// };
17 changes: 14 additions & 3 deletions lib/requests/views/recording_prompt.view.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,21 @@
<form ng-submit='startRecording()' ng-hide='COUNTDOWN'>
<h2>Briefly name your request. (e.g. javascript event handler syntax)</h2>
<textarea ng-model='requestTitle' id="request-title" class="form-control native-key-bindings" rows="1" tabIndex=-1 placeholder="(e.g. javascript event handler syntax)">{{requestTitle}}</textarea>
<h2>Pressing "Start Recording" button below will start recording your voice and text written in the editor. Be ready to speak!</h2>
<h2 style="color:red;">Please keep your request within 1 minute.</h2>
<h2 ng-hide='TEXTMODE'>
You have two options to describe your request:<br><br>
1. Pressing "Text" button below allows you to write your request. <br><br>
2. Pressing "Start Recording" button below will start recording your voice and text written in the editor.
</h2>
<h2 ng-hide='TEXTMODE' style="color:red;">Please keep your request within 1 minute.</h2>
<br/>
<h2 ng-show='TEXTMODE' >Describe your request in the text box below. Click 'Submit' button once you are done! (up to 50 words)</h2>

<textarea ng-show='TEXTMODE' ng-model='textRequestDescription' id="request-text" class="form-control native-key-bindings" rows="5" tabIndex=-1 placeholder="(e.g. type your request here ... )">{{requestText}}</textarea>

<div ng-hide="COUNTDOWN" class="prompt_buttons">
<button id='startRecording' type='button' class='btn btn-default icon icon-primitive-dot settings h3_size' ng-click='startRecording()'>Start Recording</button>
<button id='textRecording' ng-hide='TEXTMODE' type='button' class='btn btn-default icon settings h3_size' ng-click='textRecording()'>Text</button>
<button id='startRecording' ng-hide='TEXTMODE' type='button' class='btn btn-default icon icon-primitive-dot settings h3_size' ng-click='startRecording()'>Start Recording</button>
<button id='requestTextSubmittion' ng-show='TEXTMODE' type='button' class='btn btn-default icon settings h3_size' ng-click='textRequestSubmittion()'>Submit</button>
<button id='cancelRecording' type='button' class='btn btn-default icon settings h3_size' ng-click='cancelPrompt()'>Cancel</button>
</div>
</form>
Expand Down
Loading

0 comments on commit 2d8b4ee

Please sign in to comment.