Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Camusensei/9386325 to your computer and use it in GitHub Desktop.
Save Camusensei/9386325 to your computer and use it in GitHub Desktop.
### WHAT WAS CHANGED - CONTROLLER ###
findIndex = (array, callback) ->
- _i = 0
+ i = 0
- while _i < array.length
- return _i if callback(array[_i])
- _i++
- -1
+ while i < array.length
+ return i if callback(array[i])
+ i++
+ array.length
$scope.saveCurrentHtmlTemplate = () ->
$scope.isEdited = true
@@ -14,10 +14,8 @@
$scope.currentHtmlTemplate.body = $scope.currentHtmlTemplate.edited_body
currentHtmlTemplatePositionInArray = findIndex $scope.currentEditedHtmlFiles, (element) ->
return element.file_name == $scope.currentHtmlTemplate.file_name
- if currentHtmlTemplatePositionInArray == -1
- currentHtmlTemplatePositionInArray = $scope.currentEditedHtmlFiles.length
$scope.currentEditedHtmlFiles[currentHtmlTemplatePositionInArray] = $scope.currentHtmlTemplate
- console.log currentHtmlTemplatePositionInArray, 'SOME TEXT HERE'
+ console.log $scope.currentEditedHtmlFiles[currentHtmlTemplatePositionInArray].file_name, 'modified (id=', $scope.currentEditedHtmlFiles[currentHtmlTemplatePositionInArray].id, ')'
$scope.saveTemplate($scope.currentHtmlTemplate)
getControllerScope "BBCtrl", (scope) ->
scope.current_page
@@ -32,27 +30,24 @@
#Most probably need to define findIndex Inside the factory also...
#Let me teporarily put the
findIndex = (array, callback) ->
- _i = 0
+ i = 0
- while _i < array.length
- return _i if callback(array[_i])
- _i++
- -1
+ while i < array.length
+ return i if callback(array[i])
+ i++
+ i
for x in html
positionOfxInSnippets = findIndex widget.snippets_attributes, (element) ->
return element.file_name == widget.snippets_attributes.file_name
- if positionOfxInSnippets == -1
- positionOfxInSnippets = widget.snippets_attributes.length
- console.log widget.snippets_attributes.length, 'IN THE FACTORY'
widget.snippets_attributes[positionOfxInSnippets] = {} #But i think you could do equals
widget.snippets_attributes[positionOfxInSnippets].id = x.id
widget.snippets_attributes[positionOfxInSnippets].body = x.body
widget.snippets_attributes[positionOfxInSnippets].file_name = x.file_name
widget.snippets_attributes[positionOfxInSnippets].file_extension = x.file_extension
- #delete widget.snippets_attributes['partial_name'] #? go for it//
- delete widget['snippets'] #This is to delete an attribute from the array it (snipppets)
+ for x in widget.snippets_attributes
+ console.log "widget contains", x.id, "=", x.file_name
+ delete widget['snippets']
Restangular.copy(widget).put();
- #Well I wouldn't know what to change
widget.put()
### WHAT WAS CHANGED - CONTROLLER ###
findIndex = (array, callback) ->
i = 0
while i < array.length
return i if callback(array[i])
i++
array.length
$scope.saveCurrentHtmlTemplate = () ->
$scope.isEdited = true
$('#highlighter').empty()
$scope.currentHtmlTemplate.body = $scope.currentHtmlTemplate.edited_body
currentHtmlTemplatePositionInArray = findIndex $scope.currentEditedHtmlFiles, (element) ->
return element.file_name == $scope.currentHtmlTemplate.file_name
$scope.currentEditedHtmlFiles[currentHtmlTemplatePositionInArray] = $scope.currentHtmlTemplate
console.log $scope.currentEditedHtmlFiles[currentHtmlTemplatePositionInArray].file_name, 'modified (id=', $scope.currentEditedHtmlFiles[currentHtmlTemplatePositionInArray].id, ')'
$scope.saveTemplate($scope.currentHtmlTemplate)
getControllerScope "BBCtrl", (scope) ->
scope.current_page
scope.showPage scope.current_page
### FACTORY CALL FOR WHAT WAS CHANGED ###
# Pseudo-code:
# For all elements in html
# if there is a matching one in snippets_attributes, update it
# else add it
#Most probably need to define findIndex Inside the factory also...
#Let me teporarily put the
findIndex = (array, callback) ->
i = 0
while i < array.length
return i if callback(array[i])
i++
i
for x in html
positionOfxInSnippets = findIndex widget.snippets_attributes, (element) ->
return element.file_name == widget.snippets_attributes.file_name
widget.snippets_attributes[positionOfxInSnippets] = {} #But i think you could do equals
widget.snippets_attributes[positionOfxInSnippets].id = x.id
widget.snippets_attributes[positionOfxInSnippets].body = x.body
widget.snippets_attributes[positionOfxInSnippets].file_name = x.file_name
widget.snippets_attributes[positionOfxInSnippets].file_extension = x.file_extension
for x in widget.snippets_attributes
console.log "widget contains", x.id, "=", x.file_name
delete widget['snippets']
Restangular.copy(widget).put();
widget.put()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment