Skip to content

Commit da9baae

Browse files
committed
add jshint, amplification scroll by cycle number
1 parent 747b8c9 commit da9baae

File tree

6 files changed

+61
-30
lines changed

6 files changed

+61
-30
lines changed

.jshintrc

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

frontend/javascripts/app/controllers/amplification_chart_ctrl.js.coffee

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ window.ChaiBioTech.ngApp.controller 'AmplificationChartCtrl', [
2323

2424
Experiment.get(id: $stateParams.id).$promise.then (data) ->
2525
maxCycle = helper.getMaxExperimentCycle data.experiment
26+
$scope.maxCycle = maxCycle
2627
$scope.chartConfig.axes.x.ticks = helper.Xticks maxCycle
2728
$scope.chartConfig.axes.x.max = maxCycle
2829
$scope.experiment = data.experiment

frontend/javascripts/app/directives/ampli-slider.coffee

Lines changed: 47 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,59 @@ window.App.directive('ampliSlider', [
55
restrict: 'E'
66
replace: true
77
require: 'ngModel'
8+
scope:
9+
cycles: '='
810
templateUrl: 'app/views/directives/ampli-slider.html'
911
link: ($scope, elem, attrs, ngModel) ->
1012

11-
ngModel.$setViewValue 0
13+
hasInit = false
14+
CYCLES = 0
1215

13-
held = false
14-
oldX = 0
15-
oldWidth = 0
16-
newX = 0
17-
slider_offset = elem.find('.slider-holder-offset')
18-
slider_width = elem.css('width').replace /px/, ''
16+
init = ->
17+
hasInit = true
1918

20-
getOffsetWidth = ->
21-
slider_offset.css('width').replace('px', '')
19+
CYCLES = $scope.cycles-2
20+
ngModel.$setViewValue 0
2221

23-
updateModel = ->
24-
ngModel.$setViewValue(getOffsetWidth()/slider_width);
25-
$scope.$apply()
26-
27-
elem.on 'mousedown', (e) ->
28-
held = true
29-
oldX = e.pageX
30-
oldWidth = getOffsetWidth()
31-
TextSelection.disable()
32-
33-
$window.$(document).on 'mousemove', (e) ->
34-
return if !held
35-
toadd = (e.pageX - oldX)
36-
newWidth = (oldWidth*1 + toadd*1)
37-
slider_offset.css('width', newWidth + 'px')
38-
updateModel()
39-
40-
$window.$(document).on 'mouseup', (e) ->
4122
held = false
42-
TextSelection.enable()
23+
oldX = 0
24+
oldWidth = 0
25+
newX = 0
26+
slider_offset = elem.find('.slider-holder-offset')
27+
slider_width = elem.css('width').replace /px/, ''
28+
calibration_width = slider_width / (CYCLES)
29+
30+
getOffsetWidth = ->
31+
slider_offset.css('width').replace('px', '')
32+
33+
updateModel = (num_cycle) ->
34+
console.log num_cycle
35+
ngModel.$setViewValue(num_cycle);
36+
$scope.$apply()
37+
38+
elem.on 'mousedown', (e) ->
39+
held = true
40+
oldX = e.pageX
41+
oldWidth = getOffsetWidth()
42+
TextSelection.disable()
43+
44+
$window.$(document).on 'mousemove', (e) ->
45+
return if !held
46+
toadd = (e.pageX - oldX)
47+
newWidth = (oldWidth*1 + toadd*1)
48+
wRatio = newWidth / slider_width
49+
wRatio = if wRatio < 0 then 0 else wRatio
50+
wRatio = if wRatio > 1 then 1 else wRatio
51+
cycle = Math.floor(wRatio * (CYCLES))
52+
w = cycle * calibration_width
53+
slider_offset.css('width', w + 'px')
54+
updateModel cycle
55+
56+
$window.$(document).on 'mouseup', (e) ->
57+
held = false
58+
TextSelection.enable()
59+
60+
$scope.$watch 'cycles', (cycles) ->
61+
init() if cycles and !hasInit
4362

4463
]);

frontend/javascripts/app/views/experiment/amplification-chart.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
<div class="zoom-text">
6060
<b>ZOOM</b>
6161
</div>
62-
<ampli-slider ng-model="ampli_zoom"></ampli-slider>
62+
<ampli-slider ng-model="ampli_zoom" cycles="maxCycle"></ampli-slider>
6363
</div>
6464
</div>
6565
<div class="col-md-6 ampli-scrollbar-container">

frontend/tasks/javascripts.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var templateCache = require('gulp-angular-templatecache');
33
var htmlmin = require('gulp-html-minifier');
44
var concat = require('gulp-concat');
55
var coffee = require('gulp-coffee');
6+
var jshint = require('gulp-jshint');
67
var babel = require('gulp-babel');
78
var rename = require('gulp-rename');
89
var replace = require('gulp-replace');
@@ -126,7 +127,14 @@ gulp.task('copy-js-to-tmp', ['clean-js', 'templates'], function () {
126127
.pipe(gulp.dest('.tmp/js'));
127128
});
128129

129-
gulp.task('concat-js', ['clean-js', 'coffee', 'es6', 'copy-js-to-tmp', 'templates'], function () {
130+
gulp.task('jslint', ['clean-js', 'coffee', 'es6', 'copy-js-to-tmp', 'templates'], function () {
131+
132+
return gulp.src('./frontend/javascripts/app/**/*.js')
133+
.pipe(jshint())
134+
.pipe(jshint.reporter('default'));
135+
});
136+
137+
gulp.task('concat-js', ['clean-js', 'coffee', 'es6', 'copy-js-to-tmp', 'templates', 'jslint'], function () {
130138
var files = vendorFiles.concat(appFiles);
131139

132140
for (var i = files.length - 1; i >= 0; i--) {

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@
2121
"gulp-cssnano": "^2.0.0",
2222
"gulp-hash-filename": "^1.0.1",
2323
"gulp-html-minifier": "^0.1.6",
24+
"gulp-jshint": "^2.0.0",
2425
"gulp-rename": "^1.2.2",
2526
"gulp-replace": "^0.5.4",
2627
"gulp-sass": "^2.0.4",
2728
"gulp-strip-debug": "^1.0.2",
2829
"gulp-uglify": "^1.4.0",
2930
"gulp-util": "^3.0.6",
3031
"gulp-watch": "^4.3.5",
32+
"jshint": "^2.8.0",
3133
"require-dir": "^0.3.0",
3234
"shelljs": "^0.5.3"
3335
},

0 commit comments

Comments
 (0)