From f0869ba2b788a34512c6f5a8cfa027f841fd5e10 Mon Sep 17 00:00:00 2001
From: Matheus Paiva {{ MSGS['Merge branches'] }}
+ | + ++ {{ commit.author }} + | ++ + {{ commit.message | limitTo: 100 }}{{ commit.message.length > 100 ? '...' : ''}} + + | ++ {{ commit.hash }} + | ++ {{ commit.date.toLocaleString() }} + | +
',
From 15791bb27ab62b4b0926b22ddf1925f3295105ee Mon Sep 17 00:00:00 2001
From: Matheus Paiva
Date: Mon, 7 Mar 2016 13:13:23 -0300
Subject: [PATCH 05/17] Created search feature
Now is possible search for:
- Author
- Message
- Files
TODO: Docs for the shortcut to toggle the search block
---
app/core/git.js | 30 ++++++--
app/frontend/modules/attributes.js | 25 +++----
app/frontend/modules/content.js | 86 +++++++++++++++++++++--
app/frontend/modules/header.js | 7 ++
app/frontend/view/content/pieContent.html | 25 ++++++-
resources/sass/all.scss | 28 +++++++-
6 files changed, 168 insertions(+), 33 deletions(-)
diff --git a/app/core/git.js b/app/core/git.js
index cd04063..6310fee 100644
--- a/app/core/git.js
+++ b/app/core/git.js
@@ -122,12 +122,29 @@ Git.prototype.getCurrentBranch = function (path, callback) {
* @param {function} callback - Callback to be execute in error or success case
*/
Git.prototype.getCommitHistory = function (opts, callback) {
- var emoji = require('./emoji');
+ let emoji = require('./emoji'),
+ skip = (opts.skip ? `--skip ${opts.skip}` : ''),
+ filter = '',
+ command;
+
+ if (opts.filter && opts.filter.text) {
+
+ switch (opts.filter.type) {
+ case 'MESSAGE':
+ filter = `--grep="${opts.filter.text}"`;
+ break;
+ case 'AUTHOR':
+ filter = `--author="${opts.filter.text}"`;
+ break;
+ case 'FILE':
+ filter = `-- ${opts.filter.text}`;
+ break;
+ }
+ }
+
+ command = `git --no-pager log -n 25 --pretty=format:%an-gtseparator-%cr-gtseparator-%h-gtseparator-%s-gtseparator-%b-gtseparator-%ae-gtseparator-%p-pieLineBreak- ${skip} ${filter}`;
- performCommand(
- "git --no-pager log -n 50 --pretty=format:%an-gtseparator-%cr-gtseparator-%h-gtseparator-%s-gtseparator-%b-gtseparator-%ae-pieLineBreak-" + (opts.skip ? ' --skip '.concat(opts.skip) : '' ),
- opts.path,
- function (error, stdout, stderr) {
+ performCommand(command, opts.path, function (error, stdout, stderr) {
var lines = stdout.split('-pieLineBreak-'),
historyList = [],
err = null;
@@ -147,7 +164,8 @@ Git.prototype.getCommitHistory = function (opts, callback) {
hash: historyItem[2],
message: emoji.parse(historyItem[3]),
body: historyItem[4],
- email: historyItem[5]
+ email: historyItem[5],
+ parentHash: historyItem[6]
});
}
}
diff --git a/app/frontend/modules/attributes.js b/app/frontend/modules/attributes.js
index e786251..5245f0e 100644
--- a/app/frontend/modules/attributes.js
+++ b/app/frontend/modules/attributes.js
@@ -2,7 +2,6 @@
angular.module('attributes', [])
.directive('ngRightClick', function($parse) {
-
return function(scope, element, attrs) {
var fn = $parse(attrs.ngRightClick);
@@ -17,7 +16,6 @@
})
.directive('ngScroll', function ($parse) {
-
return function (scope, element, attrs) {
var fn = $parse(attrs.ngScroll);
@@ -31,22 +29,17 @@
};
})
- .directive('ngInputChange', function ($parse) {
-
- return {
- restrict: 'A',
- require: '?ngModel',
-
- link: function(scope, element, attrs, ngModel) {
+ .directive('ngEnter', function() {
+ return function(scope, element, attrs) {
- element.on('change', function (e) {
+ element.bind("keydown keypress", function(event) {
- if (ngModel) {
- ngModel.$setViewValue(e.srcElement.value);
- }
- });
- }
+ if (event.which === 13) {
+ scope.$apply(function() {
+ scope.$eval(attrs.ngEnter);
+ });
+ }
+ });
};
});
-
})();
diff --git a/app/frontend/modules/content.js b/app/frontend/modules/content.js
index ae81149..2b1db2d 100644
--- a/app/frontend/modules/content.js
+++ b/app/frontend/modules/content.js
@@ -60,7 +60,12 @@
if (!forceReload) {
this.setCommitMessage(null);
this.setCommitDescription(null);
-
+
+ // Reset filter info
+ this.searchCommitFilter.text = null;
+ this.showNoMatchFilterMessage = false;
+ this.enableSearchBlock = false;
+
notification = new GPNotification(`${MSGS['Opening repository']} ${repository.name}`, { showLoad: true });
notification.pop();
@@ -107,15 +112,13 @@
}
};
- this.showCommitChanges = function (commit, commitIndex) {
- var ancestorCommit = this.repositoryHistory[commitIndex+1] || {},
- opts = {
+ this.showCommitChanges = function (commit) {
+ var opts = {
hash: commit.hash,
- ancestorHash: ancestorCommit.hash || '',
+ ancestorHash: commit.parentHash,
path: selectedRepository.path
};
- selectedCommitAncestor = ancestorCommit;
CommomService.selectedCommit = commit;
this.loadingChanges = true;
@@ -336,7 +339,8 @@
GIT.getCommitHistory({
path: selectedRepository.path,
- skip: this.repositoryHistory.length
+ skip: this.repositoryHistory.length,
+ filter: this.searchCommitFilter
}, function (err, historyList) {
if (err) {
@@ -754,6 +758,74 @@
return CommomService.isRepoListEmpty();
};
+ this.enableSearchBlock = false;
+
+ this.searchCommitFilter = {
+ types: [
+ 'MESSAGE',
+ 'FILE',
+ 'AUTHOR'
+ ],
+ type: 'MESSAGE',
+ text: null
+ };
+
+ this.showNoMatchFilterMessage = false;
+
+ this.toogleSearchBlock = function () {
+ this.enableSearchBlock = !this.enableSearchBlock;
+
+ if (!this.enableSearchBlock) {
+ this.repositoryHistory = [];
+ this.searchCommitFilter.text = null;
+ this.showNoMatchFilterMessage = false;
+
+ GIT.getCommitHistory({
+ path: selectedRepository.path
+ }, function (err, historyList) {
+
+ if (err) {
+ alert(MSGS['Error getting more history. Error: '] + err.message);
+ } else {
+ this.repositoryHistory = historyList;
+
+ applyScope($scope);
+ }
+
+ }.bind(this));
+ }
+ }.bind(this);
+
+ this.filterCommits = function () {
+
+ if (this.searchCommitFilter.text) {
+ this.commitHistory = [];
+ selectedCommit = null;
+
+ GIT.getCommitHistory({
+ path: selectedRepository.path,
+ filter: this.searchCommitFilter
+ }, function (err, historyList) {
+
+ if (err) {
+ alert(MSGS['Error getting more history. Error: '] + err.message);
+ } else {
+
+ if (historyList.length > 0) {
+ this.showNoMatchFilterMessage = false;
+
+ this.repositoryHistory = historyList;
+ } else {
+ this.showNoMatchFilterMessage = true;
+ }
+
+ applyScope($scope);
+ }
+
+ }.bind(this));
+ }
+ };
+
// Listener to "showStashDiff" event fired on click View file on a Stash
$scope.$on('showStashDiff', function (event, stash, files) {
this.stash.info = stash;
diff --git a/app/frontend/modules/header.js b/app/frontend/modules/header.js
index 9d85e80..7b5b6ca 100644
--- a/app/frontend/modules/header.js
+++ b/app/frontend/modules/header.js
@@ -717,6 +717,13 @@
applyScope($scope);
}.bind(this));
+ // Toggle search commits block
+ globalShortcut.register('ctrl+shift+f', function () {
+ $scope.appCtrl.toogleSearchBlock();
+
+ applyScope($scope);
+ }.bind(this));
+
}.bind(this);
registerShortcuts();
diff --git a/app/frontend/view/content/pieContent.html b/app/frontend/view/content/pieContent.html
index 4cc1815..1104569 100644
--- a/app/frontend/view/content/pieContent.html
+++ b/app/frontend/view/content/pieContent.html
@@ -51,7 +51,26 @@
-