Просмотр исходного кода

Change strategy to store selected label; improve the history toolbar layout to accomodate larger labels; fix issues with layout not being updated when changing history view modes.

Paulo Reis 8 лет назад
Родитель
Сommit
2ee42af1de

+ 2 - 1
services/web/app/views/project/editor/history/entriesListV2.pug

@@ -20,6 +20,7 @@ aside.change-list(
 		current-user="user"
 		current-user="user"
 		users="projectUsers"
 		users="projectUsers"
 		is-loading="history.loading"
 		is-loading="history.loading"
+		selected-label="history.selection.label"
 		on-label-select="handleLabelSelect(label)"
 		on-label-select="handleLabelSelect(label)"
 		on-label-delete="handleLabelDelete(label)"
 		on-label-delete="handleLabelDelete(label)"
 	)
 	)
@@ -209,7 +210,7 @@ script(type="text/ng-template", id="historyLabelsListTpl")
 		.history-entry-label(
 		.history-entry-label(
 			ng-repeat="label in $ctrl.labels track by label.id"
 			ng-repeat="label in $ctrl.labels track by label.id"
 			ng-click="$ctrl.onLabelSelect({ label: label })"
 			ng-click="$ctrl.onLabelSelect({ label: label })"
-			ng-class="{ 'history-entry-label-selected': label.selected }" 
+			ng-class="{ 'history-entry-label-selected': label.id === $ctrl.selectedLabel.id }" 
 		)
 		)
 			history-label(
 			history-label(
 				show-tooltip="false"
 				show-tooltip="false"

+ 22 - 15
services/web/app/views/project/editor/history/toolbarV2.pug

@@ -2,24 +2,31 @@
 	ng-controller="HistoryV2ToolbarController"
 	ng-controller="HistoryV2ToolbarController"
 	ng-if="ui.view == 'history' && history.isV2 && history.viewMode === HistoryViewModes.POINT_IN_TIME"
 	ng-if="ui.view == 'history' && history.isV2 && history.viewMode === HistoryViewModes.POINT_IN_TIME"
 )
 )
-	span(ng-show="history.loadingFileTree")
+	span.history-toolbar-selected-version(ng-show="history.loadingFileTree")
 		i.fa.fa-spin.fa-refresh
 		i.fa.fa-spin.fa-refresh
 		|    #{translate("loading")}...
 		|    #{translate("loading")}...
-	span(ng-show="!history.loadingFileTree") #{translate("browsing_project_as_of")} 
+	span.history-toolbar-selected-version(
+		ng-show="!history.loadingFileTree && !history.showOnlyLabels"
+	) #{translate("browsing_project_as_of")} 
 		time.history-toolbar-time {{ history.selection.updates[0].meta.end_ts | formatDate:'Do MMM YYYY, h:mm a' }}
 		time.history-toolbar-time {{ history.selection.updates[0].meta.end_ts | formatDate:'Do MMM YYYY, h:mm a' }}
-	button.history-toolbar-btn(
-		ng-click="showAddLabelDialog();"
-		ng-if="!history.showOnlyLabels"
-		ng-disabled="history.loadingFileTree"
-	) 
-		i.fa.fa-tag
-		|  #{translate("history_label_this_version")}
-	button.history-toolbar-btn(
-		ng-click="toggleHistoryViewMode();"
-		ng-disabled="history.loadingFileTree"
-	) 
-		i.fa.fa-exchange
-		|  #{translate("compare_to_another_version")}
+	span.history-toolbar-selected-version(
+		ng-show="!history.loadingFileTree && history.showOnlyLabels && history.selection.label"
+	) Browsing project version labelled 
+		span.history-toolbar-selected-label "{{ history.selection.label.comment }}"
+	div.history-toolbar-actions
+		button.history-toolbar-btn(
+			ng-click="showAddLabelDialog();"
+			ng-if="!history.showOnlyLabels"
+			ng-disabled="history.loadingFileTree"
+		) 
+			i.fa.fa-tag
+			|  #{translate("history_label_this_version")}
+		button.history-toolbar-btn(
+			ng-click="toggleHistoryViewMode();"
+			ng-disabled="history.loadingFileTree"
+		) 
+			i.fa.fa-exchange
+			|  #{translate("compare_to_another_version")}
 
 
 	.history-toolbar-entries-list
 	.history-toolbar-entries-list
 		toggle-switch(
 		toggle-switch(

+ 17 - 14
services/web/public/coffee/ide/history/HistoryV2Manager.coffee

@@ -38,6 +38,9 @@ define [
 				else
 				else
 					@reset()
 					@reset()
 					@$scope.history.viewMode = HistoryViewModes.COMPARE
 					@$scope.history.viewMode = HistoryViewModes.COMPARE
+				@ide.$timeout () =>
+					@$scope.$broadcast "history:toggle"
+				, 0
 
 
 			@$scope.$watch "history.selection.updates", (updates) =>
 			@$scope.$watch "history.selection.updates", (updates) =>
 				if @$scope.history.viewMode == HistoryViewModes.COMPARE
 				if @$scope.history.viewMode == HistoryViewModes.COMPARE
@@ -57,6 +60,7 @@ define [
 					if showOnlyLabels
 					if showOnlyLabels
 						@selectedLabelFromUpdatesSelection()
 						@selectedLabelFromUpdatesSelection()
 					else
 					else
+						@$scope.history.selection.label = null
 						if @$scope.history.selection.updates.length == 0
 						if @$scope.history.selection.updates.length == 0
 							@autoSelectLastUpdate()
 							@autoSelectLastUpdate()
 
 
@@ -79,6 +83,7 @@ define [
 				nextBeforeTimestamp: null
 				nextBeforeTimestamp: null
 				atEnd: false
 				atEnd: false
 				selection: {
 				selection: {
+					label: null
 					updates: []
 					updates: []
 					docs: {}
 					docs: {}
 					pathname: null
 					pathname: null
@@ -166,21 +171,17 @@ define [
 				
 				
 		selectLabel: (labelToSelect) ->
 		selectLabel: (labelToSelect) ->
 			updateToSelect = null
 			updateToSelect = null
-			alreadySelected = false
+
+			if @_isLabelSelected labelToSelect
+				# Label already selected
+				return
+
 			for update in @$scope.history.updates
 			for update in @$scope.history.updates
 				if update.toV == labelToSelect.version
 				if update.toV == labelToSelect.version
 					updateToSelect = update
 					updateToSelect = update
 					break
 					break
 
 
-			for label in @$scope.history.labels
-				matchingLabel = (labelToSelect.id == label.id)
-				if matchingLabel and label.selected
-					alreadySelected = true
-				label.selected = matchingLabel
-
-			if alreadySelected
-				return
-
+			@$scope.history.selection.label = labelToSelect
 			if updateToSelect?
 			if updateToSelect?
 				@selectUpdate updateToSelect
 				@selectUpdate updateToSelect
 			else
 			else
@@ -241,10 +242,9 @@ define [
 			pathname = @$scope.history.selection.pathname
 			pathname = @$scope.history.selection.pathname
 			if @$scope.history.selection.updates?[0]?
 			if @$scope.history.selection.updates?[0]?
 				toV = @$scope.history.selection.updates[0].toV
 				toV = @$scope.history.selection.updates[0].toV
-			else
-				for label in @$scope.history.labels or []
-					if label.selected
-						toV = label.version
+			else if @$scope.history.selection.label?
+				toV = @$scope.history.selection.label.version
+
 			if !toV?
 			if !toV?
 				return
 				return
 			url = "/project/#{@$scope.project_id}/diff"
 			url = "/project/#{@$scope.project_id}/diff"
@@ -316,6 +316,9 @@ define [
 			}).then (response) =>
 			}).then (response) =>
 				@_deleteLabelLocally label
 				@_deleteLabelLocally label
 
 
+		_isLabelSelected: (label) ->
+			label.id == @$scope.history.selection.label?.id
+
 		_deleteLabelLocally: (labelToDelete) ->
 		_deleteLabelLocally: (labelToDelete) ->
 			for update, i in @$scope.history.updates
 			for update, i in @$scope.history.updates
 				if update.toV == labelToDelete.version
 				if update.toV == labelToDelete.version

+ 2 - 1
services/web/public/coffee/ide/history/components/historyLabelsList.coffee

@@ -16,7 +16,7 @@ define [
 		ctrl.getUserCSSStyle = (user, label) ->
 		ctrl.getUserCSSStyle = (user, label) ->
 			curUserId = user?._id or user?.id
 			curUserId = user?._id or user?.id
 			hue = ColorManager.getHueForUserId(curUserId) or 100
 			hue = ColorManager.getHueForUserId(curUserId) or 100
-			if label.selected
+			if label.id == ctrl.selectedLabel?.id
 				color : "#FFF" 
 				color : "#FFF" 
 			else 
 			else 
 				color: "hsl(#{ hue }, 70%, 50%)"
 				color: "hsl(#{ hue }, 70%, 50%)"
@@ -28,6 +28,7 @@ define [
 			users: "<"
 			users: "<"
 			currentUser: "<"
 			currentUser: "<"
 			isLoading: "<"
 			isLoading: "<"
+			selectedLabel: "<"
 			onLabelSelect: "&"
 			onLabelSelect: "&"
 			onLabelDelete: "&"
 			onLabelDelete: "&"
 		controller: historyLabelsListController
 		controller: historyLabelsListController

+ 19 - 13
services/web/public/stylesheets/app/editor/history-v2.less

@@ -15,22 +15,28 @@
 .history-toolbar when (@is-overleaf = false) {
 .history-toolbar when (@is-overleaf = false) {
 	border-bottom: @toolbar-border-bottom;
 	border-bottom: @toolbar-border-bottom;
 }
 }
-	.history-toolbar-time {
-		font-weight: bold;
+	.history-toolbar-selected-version {
+		white-space: nowrap;
+		overflow: hidden;
+		text-overflow: ellipsis;
 	}
 	}
-	.history-toolbar-btn {
-		.btn;
-		.btn-info;
-		.btn-xs;
-		padding-left: @padding-small-horizontal;
-		padding-right: @padding-small-horizontal;
-		margin-left: (@line-height-computed / 2);
+		.history-toolbar-time,
+		.history-toolbar-selected-label {
+			font-weight: bold;
+		}
+	.history-toolbar-actions {
+		flex-grow: 1;
 	}
 	}
-
+		.history-toolbar-btn {
+			.btn;
+			.btn-info;
+			.btn-xs;
+			padding-left: @padding-small-horizontal;
+			padding-right: @padding-small-horizontal;
+			margin-left: (@line-height-computed / 2);
+		}
 	.history-toolbar-entries-list {
 	.history-toolbar-entries-list {
-		position: absolute; 
-		right: 0;
-		width: @changesListWidth;
+		flex: 0 0 @changesListWidth;
 		padding: 0 10px;
 		padding: 0 10px;
 		border-left: 1px solid @editor-border-color;
 		border-left: 1px solid @editor-border-color;
 	}
 	}