Skip to content

Commit

Permalink
Merge pull request #920 from MetadataConsulting/MET-1389_HistoryLog
Browse files Browse the repository at this point in the history
MET-1389 Update History Tab for all elements, By Type Version Author …
  • Loading branch information
davidmilward authored Feb 6, 2017
2 parents b1c4eb1 + 528d4d9 commit 8beec12
Show file tree
Hide file tree
Showing 12 changed files with 129 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
data-value-for="{{property.label}}" ng-switch-when="element">
<span ng-class="theValue.getIcon()" class="text-muted"></span>
<a ng-click="theValue.show()">{{theValue.name}}</a>
<small><a ng-href="{{theValue.dataModel.href()}}" class="label"
<small ng-if="theValue.dataModel"><a ng-href="{{theValue.dataModel.href()}}" class="label"
ng-class="{'label-warning': theValue.getDataModelStatus() == 'DRAFT', 'label-info': theValue.getDataModelStatus() == 'PENDING', 'label-primary': theValue.getDataModelStatus() == 'FINALIZED', 'label-danger': theValue.getDataModelStatus() == 'DEPRECATED'}">
{{theValue.getDataModelWithVersion()}}
</a>
Expand All @@ -38,16 +38,40 @@
</div>
</div>
</td>
<td class="pp-table-property-value-no-wrap col-md-8 pp-table-property-element-value"
data-value-for="{{property.label}}" ng-switch-when="relationship">
<span ng-class="theValue.getIcon()" class="text-muted"></span>
<a ng-href="{{theValue.source.href()}}"><span ng-class="theValue.source.getIcon()" class="text-muted"></span> {{theValue.source.name}}</a>
<small ng-if="theValue.source.dataModel"><a ng-href="{{theValue.source.dataModel.href()}}" class="label"
ng-class="{'label-warning': theValue.source.getDataModelStatus() == 'DRAFT', 'label-info': theValue.source.getDataModelStatus() == 'PENDING', 'label-primary': theValue.source.getDataModelStatus() == 'FINALIZED', 'label-danger': theValue.source.getDataModelStatus() == 'DEPRECATED'}">
{{theValue.source.getDataModelWithVersion()}}
</a>
</small>

{{theValue.type.name}}
<a ng-href="{{theValue.destination.href()}}"><span ng-class="theValue.destination.getIcon()" class="text-muted"></span> {{theValue.destination.name}}</a>
<small ng-if="theValue.destination.dataModel"><a ng-href="{{theValue.destination.dataModel.href()}}" class="label"
ng-class="{'label-warning': theValue.destination.getDataModelStatus() == 'DRAFT', 'label-info': theValue.destination.getDataModelStatus() == 'PENDING', 'label-primary': theValue.destination.getDataModelStatus() == 'FINALIZED', 'label-danger': theValue.destination.getDataModelStatus() == 'DEPRECATED'}">
{{theValue.destination.getDataModelWithVersion()}}
</a>
</small>
</td>
<td class="pp-table-property-value col-md-8 pp-table-property-element-value" data-value-for="{{property.label}}"
ng-switch-when="date">{{theValue | date:'short'}}
</td>
<td class="pp-table-property-value col-md-8 pp-table-property-element-value" data-value-for="{{property.label}}"
ng-switch-when="orderedMap">
<div class="preserve-new-lines">
<span ng-bind-html="printOrderedMap(theValue)"></span>
</div>
</td>
<td class="pp-table-property-value col-md-8 pp-table-property-element-value" data-value-for="{{property.label}}"
ng-switch-when="elementArray">
<span ng-repeat="element in theValue track by element.link">
<a class="label with-pointer" ng-href="{{element.href()}}">
<span ng-class="element.getIcon()"></span>
{{element.name}}
<small>
<small <small ng-if="element.dataModel">>
<a ng-href="{{element.dataModel.href()}}" class="label"
ng-class="{'label-warning': element.getDataModelStatus() == 'DRAFT', 'label-info': element.getDataModelStatus() == 'PENDING', 'label-primary': element.getDataModelStatus() == 'FINALIZED', 'label-danger': element.getDataModelStatus() == 'DEPRECATED'}">
{{element.getDataModelWithVersion()}}
Expand All @@ -64,7 +88,10 @@
</span>
</td>
<td class="pp-table-property-value col-md-8 pp-table-property-element-value" data-value-for="{{property.label}}"
ng-switch-default ng-bind-html="theValue == null ? '' : ('' + theValue) | linky:'_blank'">
ng-switch-when="text" ng-bind-html="trustedHtml(theValue == null ? '' : ('' + theValue))">
</td>
<td class="pp-table-property-value col-md-8 pp-table-property-element-value" data-value-for="{{property.label}}"
ng-switch-default ng-bind-html="trustedHtml(theValue == null ? '' : ('' + theValue))">
</td>
</tr>
</tbody>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ angular.module('mc.core.ui.bs.catalogueElementActions', ['mc.util.ui.actions']).
icon: 'fa fa-fw fa-arrow-circle-up'
type: 'primary'
watches: ['element.status', 'element.archived']
disabled: $scope.element.archived || $scope.element.status == 'DRAFT' || $scope.element.status == 'PENDING' ||
$scope.element.history.total != $scope.element.versionNumber
disabled: $scope.element.archived || $scope.element.status == 'DRAFT' || $scope.element.status == 'PENDING'
action: ->
messages.prompt(null, null, type: 'new-version', element: $scope.element)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,6 @@ angular.module('mc.core.ui.bs.catalogueElementProperties', []).config ['catalogu
{header: "Description", value: 'relation.description', class: 'col-md-7'}
]

catalogueElementPropertiesProvider.configureProperty 'history', {
columns: [
{header: "Version", value: 'versionNumber', class: 'col-md-1', href: 'href()'}
{header: "Name", value: 'name', class: 'col-md-5', href: 'href()'}
{header: "Description", value: 'description', class: 'col-md-6'}
]
}

catalogueElementPropertiesProvider.configureProperty 'org.modelcatalogue.core.Asset.history', {
hidden: (security) ->
!security.hasRole('CURATOR')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ angular.module('mc.core.ui.infiniteListCtrl', ['mc.core.listEnhancer']).controll
properties.push label: 'Property', value: -> element.property
properties.push label: 'Old Value', value: -> if element.oldValue?.value then element.oldValue.value else element.oldValue
properties.push label: 'New Value', value: -> if element.newValue?.value then element.newValue.value else element.newValue
if element.difference
properties.push label: 'Difference', value: -> element.difference
properties

getRowForElement = (element, oldRow) ->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
angular.module('mc.core.ui.propertiesPane', []).directive 'propertiesPane', [-> {
angular.module('mc.core.ui.propertiesPane', ['ngSanitize']).directive 'propertiesPane', [-> {
restrict: 'E'
replace: true
scope:
Expand All @@ -9,7 +9,7 @@ angular.module('mc.core.ui.propertiesPane', []).directive 'propertiesPane', [->

templateUrl: '/mc/core/ui/propertiesPane.html'

controller: ['$scope', ($scope) ->
controller: ($scope, $sce) ->
if not $scope.properties
$scope.properties = []
if $scope.item?.type == 'orderedMap'
Expand All @@ -19,6 +19,8 @@ angular.module('mc.core.ui.propertiesPane', []).directive 'propertiesPane', [->
for key, value of $scope.item
$scope.properties.push {label: key, value: value}

$scope.trustedHtml = (plainText) -> $sce.trustAsHtml(plainText)

$scope.printObject = (object) ->
vals = []
for key, value of object
Expand All @@ -29,14 +31,19 @@ angular.module('mc.core.ui.propertiesPane', []).directive 'propertiesPane', [->
vals.push "#{key}: #{value ? ''}"
vals.join('\n')

$scope.printOrderedMap = (orderedMap) ->
return '' unless orderedMap
theMap = if angular.isString(orderedMap) then angular.fromJson(orderedMap) else orderedMap
enumerations = []
enumerations.push "#{enumeration.key}: #{enumeration.value}" for enumeration in theMap.values
enumerations.join('\n')

$scope.getEnumerations = (enumeratedType) ->
return '' if not enumeratedType
return """<a href="#/catalogue/dataClass/#{enumeratedType.dataClass.id}"><span class="fa fa-fw fa-cubes"></span> #{enumeratedType.dataClass.name}</a>""" if enumeratedType.dataClass
return enumeratedType.description if not enumeratedType.enumerations
return enumeratedType.description if not enumeratedType.enumerations.values
enumerations = []
enumerations.push "#{enumeration.key}: #{enumeration.value}" for enumeration in enumeratedType.enumerations.values
enumerations.join('\n')
$scope.printOrderedMap(enumeratedType.enumerations)

$scope.evaluateValue = (value, element) ->
if angular.isFunction(value) then value(element) else $scope.$eval(value, element)
Expand All @@ -55,7 +62,9 @@ angular.module('mc.core.ui.propertiesPane', []).directive 'propertiesPane', [->
return 'date' if angular.isDate(target)
return 'elementArray' if angular.isArray(target) and target.length > 0 and target[0] and target[0].elementType
return 'array' if angular.isArray(target)
return 'relationship' if angular.isObject(target) and target.source? and target.destination?
return 'element' if angular.isObject(target) and target.show? and angular.isFunction(target.show)
return 'orderedMap' if angular.isString(target) and target.indexOf('"type":"orderedMap"') >= 0
return 'text'

$scope.expandOrCollapse = (element) ->
Expand All @@ -75,6 +84,5 @@ angular.module('mc.core.ui.propertiesPane', []).directive 'propertiesPane', [->
element._expanding = false
element._expanded = true

]
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -875,14 +875,8 @@ abstract class AbstractCatalogueElementController<T extends CatalogueElement> ex

params.max = Math.min(max ?: 10, 100)

Map<String, Object> customParams = [:]
customParams.putAll params

customParams.sort = historySortProperty
customParams.order = historyOrderDirection


respond CatalogueElementService.getAllVersions(customParams, element)
respond Lists.wrap(params, "/${resourceName}/${params.id}/history", auditService.getElementChanges(params, element.latestVersionId ?: element.id))
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class Change {
version false
newValue type: 'text'
oldValue type: 'text'
latestVersionId index: 'change_idx_4'
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.modelcatalogue.core.audit

import com.google.common.collect.ImmutableList
import grails.gorm.DetachedCriteria
import grails.util.Holders
import org.hibernate.SessionFactory
Expand Down Expand Up @@ -228,6 +229,26 @@ class AuditService {
}
}

ListWithTotalAndType<Change> getElementChanges(Map params, Long latestVersionId){
if (!params.sort) {
params.sort = 'dateCreated'
params.order = 'desc'
}


Lists.fromCriteria(params, Change) {
eq 'latestVersionId', latestVersionId
isNull('parentId')
ne 'system', Boolean.TRUE
ne 'otherSide', Boolean.TRUE
not {
inList('type', ImmutableList.of(ChangeType.NEW_VERSION_CREATED, ChangeType.NEW_ELEMENT_CREATED, ChangeType.ELEMENT_DEPRECATED))
}

}

}

CatalogueElement logNewVersionCreated(CatalogueElement element, Closure<CatalogueElement> createDraftBlock) {
Long changeId = auditor.get().logNewVersionCreated(element, modelCatalogueSecurityService.currentUser?.id).toBlocking().first()
CatalogueElement ce = withParentId(changeId, createDraftBlock)
Expand Down Expand Up @@ -266,6 +287,7 @@ class AuditService {
withDefaultAuthorAndParentAction(authorId ,auditor.get().logExternalChange(source, message, modelCatalogueSecurityService.currentUser?.id).toBlocking().first(), createDraftBlock)
}


void logNewMetadata(ExtensionValue extension) {
auditor.get().logNewMetadata(extension, modelCatalogueSecurityService.currentUser?.id)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ abstract class CatalogueElementMarshaller extends AbstractMarshaller {
versionNumber : el.versionNumber,
status : el.status.toString(),
versionCreated : el.versionCreated,
history : [count: el.countVersions(), itemType: type.name, link: "/${GrailsNameUtils.getPropertyName(el.getClass())}/$el.id/history".toString()],
history : [count: Integer.MAX_VALUE, itemType: type.name, link: "/${GrailsNameUtils.getPropertyName(el.getClass())}/$el.id/history".toString()],
typeHierarchy : [count: Integer.MAX_VALUE, itemType: type.name, link: "/${GrailsNameUtils.getPropertyName(el.getClass())}/$el.id/typeHierarchy".toString()]
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,6 @@ class ChangesSpec extends AbstractModelCatalogueGebSpec {

check { tab('activity') } displayed
check { tab('history') } displayed

when:
selectTab 'history'

then: "the history tab contains treeview item which does not resize"
check { $('#history-tab .catalogue-element-treeview-list-container.no-resize') }
check { $('span.catalogue-element-treeview-name', text: startsWith("admin")) }

when:
selectInTree 'admin'

then:
check { $('span.catalogue-element-treeview-name', text: "admin [1] created") }
}

def "classifications have activity feed"() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,7 @@ abstract class AbstractCatalogueElementControllerIntegrationSpec<T> extends Abst
}
}

@Unroll
def "get json history: #no where max: #max offset: #offset\""() {
CatalogueElement first = CatalogueElement.get(loadItem.id)
createDraftVersions(first)

when:
controller.params.id = first.id
controller.params.offset = offset
controller.params.max = max
controller.response.format = "json"
controller.history(max)
def json = controller.response.json

recordResult "history$no", json


then:
checkJsonCorrectListValues(json, total, size, offset, max, next, previous)
json.itemType == itemTypeForHistory

// TODO: add more verification

where:
[no, size, max, offset, total, next, previous] << optimize(getHistoryPaginationParameters("/${getResourceNameForHistory()}/${loadItem.id}/history"))
}

protected String getResourceNameForHistory() {
resourceName
Expand Down

0 comments on commit 8beec12

Please sign in to comment.