Skip to content

Commit

Permalink
fixing couple of bugs related to ordered map and tree view loading
Browse files Browse the repository at this point in the history
  • Loading branch information
musketyr committed Sep 24, 2015
1 parent fab187d commit 42f0695
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ angular.module('mc.core.orderedMapEnhancer', ['mc.util.enhance']).config ['enhan
condition = (orderedMap) -> orderedMap.hasOwnProperty('type') and orderedMap.type == 'orderedMap'
factory = [ 'enhance', (enhance)->
orderedMapEnhancer = (orderedMap) ->
ensureValuesAreArray = (map) ->
return if map.values and angular.isArray(map.values)
map.values = []

orderedMap.get = (key) -> @access(key).get()
orderedMap.access = (key) ->
self = @
set = (newValue) ->
ensureValuesAreArray(self)
for value in self.values
if value.key == key
value.value = newValue
Expand All @@ -15,6 +19,7 @@ angular.module('mc.core.orderedMapEnhancer', ['mc.util.enhance']).config ['enhan
self.values.push(key: key, value: newValue) if newValue or not key
return newValue
get = ->
ensureValuesAreArray(self)
for value in self.values
if value.key == key
return value.value
Expand All @@ -29,6 +34,7 @@ angular.module('mc.core.orderedMapEnhancer', ['mc.util.enhance']).config ['enhan
getterSetter.get = -> get()
getterSetter.set = (newValue) -> set(newValue)
getterSetter.remove = ->
ensureValuesAreArray(self)
result = undefined
for value, i in self.values[..].reverse()
if value.key == key
Expand All @@ -46,10 +52,12 @@ angular.module('mc.core.orderedMapEnhancer', ['mc.util.enhance']).config ['enhan


orderedMap.clearIfOnlyContainsPlaceholder = ->
ensureValuesAreArray(@)
if @values.length == 1 and not @values[0].value
@values = []

orderedMap.addPlaceholderIfEmpty = ->
ensureValuesAreArray(@)
if @values.length == 0
@values = [{key: ''}]
orderedMap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ angular.module('mc.core.ui.bs.catalogueElementProperties', []).config ['catalogu
isDirty: ->
if @value and enhance.isEnhancedBy(@value, 'orderedMap') and @original and enhance.isEnhancedBy(@original, 'orderedMap')
return false if angular.equals(@value.values, @original.values)
return false if @original.values.length == 0 and @value.values.length == 1 and not @value.values[0].value and not @value.values[0].key
return false if (@original.values ? []).length == 0 and @value.values.length == 1 and not @value.values[0].value and not @value.values[0].key
!angular.equals(@original, @value)
reset: -> @value = angular.copy @original
update: ->
Expand Down Expand Up @@ -267,7 +267,7 @@ angular.module('mc.core.ui.bs.catalogueElementProperties', []).config ['catalogu


if $value?.type == 'orderedMap'
for value in $value.values when not angular.isObject(value.value)
for value in ($value.values ? []) when not angular.isObject(value.value)
tabDefinition.properties.push {
label: value.key
value: getSortedMapPropertyVal(value.key)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ cetiModule.run [ '$templateCache', ($templateCache) ->
<a ng-if="!currentDescend &amp;&amp; element.elementType" class="catalogue-element-treeview-icon btn btn-link">
<span ng-class="element.getIcon()"></span>
</a>
<span class="catalogue-element-treeview-name" ng-class="{'text-warning': element.status == 'DRAFT', 'text-info': element.status == 'PENDING', 'text-danger': (element.status == 'DEPRECATED' || element.undone)}" ng-click="select(element)">{{element.$$localName || element.name}}<small class="text-muted" ng-if="element.$$localName"> {{element.name}}</small><small class="text-muted"> <span class="catalogue-element-treeview-version-number">{{element.latestVersionId}}.{{element.versionNumber}}</span></small></span>
<span class="catalogue-element-treeview-name" ng-class="{'text-warning': element.status == 'DRAFT', 'text-info': element.status == 'PENDING', 'text-danger': (element.status == 'DEPRECATED' || element.undone)}" ng-click="select(element)">{{element.$$localName || element.name}}<small class="text-muted" ng-if="element.$$localName"> {{element.name}}</small><small class="text-muted"> <span ng-if="element.latestVersionId" class="catalogue-element-treeview-version-number">{{element.latestVersionId}}.{{element.versionNumber}}</span></small></span>
<small class="text-muted" ng-if="element.href"> <a class="catalogue-element-treeview-link" ng-href="{{element.href()}}" title="{{element.$$localName || element.name}}" target="_blank"><span class="fa fa-external-link"></span></a></small>
</span>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ angular.module('mc.core.ui.catalogueElementTreeview', ['mc.core.ui.catalogueElem

addItemsFromList = (list) ->
return if list.$$children
return if not list.list
list.$$children = []
for item in list.list
cachedChild = if list.$$cachedChildren then list.$$cachedChildren[item.link]
Expand Down Expand Up @@ -76,6 +77,7 @@ angular.module('mc.core.ui.catalogueElementTreeview', ['mc.core.ui.catalogueElem

$scope.showMore = () ->
return if $scope.$$showingMore
return if not nextFun
$scope.$$showingMore = true
return unless $scope.list.total > $scope.list.$$children.length
params = {}
Expand Down

0 comments on commit 42f0695

Please sign in to comment.