Skip to content

Commit 5926a76

Browse files
authored
Merge pull request #203 from spasovski/qfixes
fix query versions logic after move to internal array
2 parents 4d5bb17 + 4c57d92 commit 5926a76

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

client/app/pages/queries/compare-query-dialog.html

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ <h4 class="modal-title">Compare Query</h4>
99
<div class="compare-query-version">
1010
<span>Compare current version to</span>
1111
<select id="version-choice" ng-model="compareQueryVersion" ng-change="$ctrl.compareQueries()">
12-
<option ng-repeat="version in $ctrl.versions" value="{{version.object_version}}">Version {{version.object_version}}</option>
12+
<option ng-repeat="version in $ctrl.versions.slice(0, $ctrl.versions.length-1)" value="{{version.object_version}}">Version {{version.object_version}}</option>
1313
</select>
1414
</div>
15-
<div class="compare-query-revert-wrapper hidden"><a ng-click="$ctrl.revertQuery()" class="btn btn-default">Revert to version {{$ctrl.previousQueryVersion}}</a></div>
15+
<div class="compare-query-revert-wrapper hidden"><a ng-click="$ctrl.revertQuery()" class="btn btn-default">Revert to version {{$ctrl.previousQueryVersion + 1}}</a></div>
1616
</div>
1717
<div>
1818
<h5>Current Version {{$ctrl.currentQuery.version}}</h5>
@@ -25,13 +25,9 @@ <h5>Current Version {{$ctrl.currentQuery.version}}</h5>
2525
</div>
2626
</div>
2727
<div>
28-
<h5>Previous Version {{$ctrl.previousQueryVersion}}</h5>
28+
<h5>Previous Version {{$ctrl.previousQueryVersion + 1}}</h5>
2929
<div class="diff-content">
30-
<p id="previous-query-diff">
31-
<span ng-class="{'diff-added': part.added, 'diff-removed': part.removed}" ng-repeat="part in $ctrl.previousDiff">
32-
{{part.value}}
33-
</span>
34-
</p>
30+
<p>{{$ctrl.previousQuery}}</p>
3531
</div>
3632
</div>
3733
</div>

client/app/pages/queries/compare-query-dialog.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,24 @@ const CompareQueryDialog = {
66
controller: ['clientConfig', '$http', function doCompare(clientConfig, $http) {
77
this.currentQuery = this.resolve.query;
88

9-
let previousQuery = '';
9+
this.previousQuery = '';
1010
this.currentDiff = [];
1111
this.previousDiff = [];
1212
this.versions = [];
13-
this.previousQueryVersion = this.currentQuery.version - 1;
13+
this.previousQueryVersion = this.currentQuery.version - 2; // due to 0-indexed versions[]
1414

15-
this.compareQueries = () => {
16-
this.previousQueryVersion = document.getElementById('version-choice').value ||
17-
this.previousQueryVersion;
15+
this.compareQueries = (isInitialLoad) => {
16+
if (!isInitialLoad) {
17+
this.previousQueryVersion = document.getElementById('version-choice').value - 1; // due to 0-indexed versions[]
18+
}
1819

19-
previousQuery = this.versions[this.previousQueryVersion].change.query.current;
20-
this.currentDiff = jsDiff.diffChars(previousQuery, this.currentQuery.query);
21-
this.previousDiff = jsDiff.diffChars(this.currentQuery.query, previousQuery);
20+
this.previousQuery = this.versions[this.previousQueryVersion].change.query.current;
21+
this.currentDiff = jsDiff.diffChars(this.previousQuery, this.currentQuery.query);
2222
document.querySelector('.compare-query-revert-wrapper').classList.remove('hidden');
2323
};
2424

2525
this.revertQuery = () => {
26-
this.resolve.query.query = previousQuery;
26+
this.resolve.query.query = this.previousQuery;
2727
this.resolve.saveQuery();
2828

2929
// Close modal.
@@ -32,6 +32,7 @@ const CompareQueryDialog = {
3232

3333
$http.get(`/api/queries/${this.currentQuery.id}/version`).then((response) => {
3434
this.versions = response.data;
35+
this.compareQueries(true);
3536
});
3637
}],
3738
scope: {

0 commit comments

Comments
 (0)