Upgrade lodash, add timestamps to step model

pull/131/head
Rick Carlino 2015-01-28 09:51:59 -06:00
parent e84422fb7b
commit a000771bba
6 changed files with 18 additions and 6795 deletions

View File

@ -20,6 +20,7 @@ gem 'high_voltage', '~> 2.1.0'
gem 'haml'
gem 'rails-assets-ng-sortable'
gem 'rails-assets-angular-data'
gem 'rails-assets-lodash'
gem 'figaro' # Store secrets the 12 factor way. TODO: Get off of this gem.
gem 'devise', github: 'plataformatec/devise'

View File

@ -203,6 +203,7 @@ GEM
rails-assets-angular (1.3.8)
rails-assets-angular-data (1.5.3)
rails-assets-angular (~> 1.0)
rails-assets-lodash (3.0.0)
rails-assets-ng-sortable (1.1.7)
rails-assets-angular (~> 1.3.0)
rails_12factor (0.0.2)
@ -321,6 +322,7 @@ DEPENDENCIES
pry
rails (= 4.1.0)
rails-assets-angular-data
rails-assets-lodash
rails-assets-ng-sortable
rails_12factor
rspec

View File

@ -11,7 +11,6 @@ controller = ($scope, Data) ->
# TODO figure out why ng-sortables breaks if passed a null value.
$scope.sequenceSteps ?= []
$scope.dragControlListeners = orderChanged: (event) ->
console.log 'DING'
position = event.dest.index
step = event.source.itemScope.modelValue
# TODO I want to do $scope.reposition(step.sequence) but cant until I resolve
@ -36,18 +35,18 @@ controller = ($scope, Data) ->
message_type: message_type
sequence_id: $scope.sequence._id
).catch(nope)
.then (step) -> $scope.sequence.steps.push(step)
.then (step) ->
$scope.sequence.steps.push(step)
$scope.reposition($scope.sequenceSteps)
$scope.load = (seq) ->
Data
.loadRelations('sequence', seq._id, ['step'])
.catch(nope)
.then ->
$scope.sequence = seq
$scope.sequenceSteps = $scope.sequence.steps
$scope.sequenceSteps = $scope.sequence.steps || []
$scope.reposition = (list) ->
# You're my best friend, LoDash. I love you. <3
sorted = _.sortBy(list, ['position', 'updated_at'])
_.each list, (val, index) ->
_.each _.sortByAll(list, ['position', 'updated_at']), (val, index) ->
val.position = index
$scope.addSequence = (params = {}, makeItDefaultNow = yes) ->
params.name ?= 'Untitled Sequence'
@ -70,19 +69,24 @@ controller = ($scope, Data) ->
.catch(nope)
$scope.copy = (obj, index) ->
return unless hasSequence()
yep = (step) -> $scope.sequence.steps.push(step)
yep = (step) ->
$scope.sequence.steps.push(step)
$scope.reposition($scope.sequenceSteps)
Data
.create('step',
sequence_id: $scope.sequence._id
message_type: obj.message_type
command: obj.command || {}
position: index + 1
position: index
).then(yep)
.catch(nope)
$scope.remove = (index) ->
# TODO Rename to deleteStep
step = $scope.sequence.steps[index]
Data.destroy('step', step._id).catch((e) -> console.error e)
Data
.destroy('step', step._id)
.catch((e) -> console.error e)
.then -> $scope.reposition($scope.sequenceSteps)
# The sequence controller supports the WYSIWYG sequence editor.
angular.module('FarmBot').controller "SequenceController", [

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,7 @@
class Step
include Mongoid::Document
include Mongoid::Orderable
include Mongoid::Timestamps
MESSAGE_TYPES = %w(single_command read_status pin_write move_abs move_rel)

View File

@ -1,5 +1,5 @@
class StepSerializer < ActiveModel::Serializer
attributes :_id, :message_type, :command, :sequence_id, :position
attributes :_id, :message_type, :command, :sequence_id, :position, :updated_at
# TODO: This is almost certainly wrong. I shouldn't need to write this method.
def sequence_id