Skip to content

Commit 4a88b97

Browse files
committed
Update settings options.
- Move settings options to a separate component. - Add settings options to the repo page. - Auto check if git is present and color the cog red if git isn't found.
1 parent e80e70a commit 4a88b97

File tree

9 files changed

+176
-120
lines changed

9 files changed

+176
-120
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
angular.module('WebgitHomeModule').component('checkSettings', {
2+
templateUrl: '/js/app/webgit-home/check-settings/check-settings.html',
3+
controllerAs: 'vm',
4+
bindings: {
5+
showOnErrorOnly: '<'
6+
},
7+
controller: ['CheckSettingsService', '$element', '$compile', '$scope', '$attrs', function (CheckSettingsService, $element, $compile, $scope, $attrs) {
8+
// debugger;
9+
var vm = this;
10+
11+
if($attrs.showOnErrorOnly) {
12+
$element.find('.home-settings-icon').addClass('show-on-error-only');
13+
}
14+
15+
vm.saveGitExecutablePath = saveGitExecutablePath;
16+
vm.viewSettingsModal = viewSettingsModal;
17+
18+
moveModalToBody();
19+
resetSettings();
20+
validateSettings();
21+
22+
bindEvents();
23+
24+
var $settingsModal = $('#settings-modal');
25+
26+
return;
27+
28+
function moveModalToBody() {
29+
var $settingsModal = $element.find('#settings-modal');
30+
//$settingsModal.appendTo('body');
31+
//$compile($settingsModal)($scope);
32+
}
33+
34+
function resetSettings() {
35+
vm.settings = {
36+
gitExists: {}
37+
};
38+
}
39+
40+
function saveGitExecutablePath() {
41+
// save vm.settings.gitExists to local storage. rescan for settings.
42+
localStorage.setItem('gitonbrowser.gitPath', vm.settings.gitExists.path);
43+
validateSettings();
44+
}
45+
46+
function bindEvents() {
47+
$('.settings-obj').on('click', '.fix-this-error', function (e) {
48+
var $settingsObj = $(e.delegateTarget);
49+
$settingsObj.find('.settings-obj-fix').toggleClass('hidden');
50+
});
51+
}
52+
53+
function viewSettingsModal() {
54+
$settingsModal.modal('show');
55+
// return validateSettings();
56+
}
57+
58+
function validateSettings() {
59+
resetSettings();
60+
var options = {};
61+
var gitExecutablePath = localStorage.getItem('gitonbrowser.gitPath') || '';
62+
if (gitExecutablePath) {
63+
options.gitExecutablePath = gitExecutablePath;
64+
}
65+
return CheckSettingsService.getSettings(options).then(function (d) {
66+
if (d.errorCode) {
67+
switch (d.errorCode) {
68+
case 1: {
69+
// git not found.
70+
vm.settings.gitExists.err = 1;
71+
vm.settings.gitExists.msg = d.msg;
72+
vm.settings.gitExists.description = d.description;
73+
break;
74+
}
75+
}
76+
vm.settings.hasError = true;
77+
}
78+
});
79+
}
80+
}]
81+
}).service('CheckSettingsService', ['$http', function ($http) {
82+
this.getSettings = getSettings;
83+
84+
return;
85+
86+
function getSettings(options) {
87+
return $http.post('/settings', options).then(function (res) {
88+
return res.data;
89+
});
90+
}
91+
}]);
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#settings-modal {
2+
font-size: 1rem;
3+
text-align: left;
4+
font-weight: normal;
5+
}
6+
7+
.home-settings-icon {
8+
cursor: pointer;
9+
color: #007bff;
10+
font-size: 25px;
11+
vertical-align: middle;
12+
}
13+
14+
.home-settings-icon.show-on-error-only {
15+
display: none;
16+
}
17+
18+
.home-settings-icon.show-on-error-only.has-error {
19+
display: inline-block;
20+
}
21+
22+
.home-settings-icon:hover {
23+
color: #6c757d;
24+
}
25+
26+
.home-settings-icon.has-error {
27+
color: #dc3545;
28+
}
29+
30+
.settings-obj .fix-this-error {
31+
display: none;
32+
cursor: pointer;
33+
}
34+
35+
.settings-obj .failed-setting .fix-this-error {
36+
display: block;
37+
}
38+
39+
.settings-obj-fix.hidden {
40+
display: none;
41+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<link href="/js/app/webgit-home/check-settings/check-settings.css" rel="stylesheet" />
2+
<span ng-click="vm.viewSettingsModal()" class="fa fa-gear home-settings-icon" ng-class="vm.settings.hasError ? 'has-error' : ''"></span>
3+
4+
<div class="modal fade" id="settings-modal" tabindex="-1" role="dialog">
5+
<div class="modal-dialog modal-lg" role="document">
6+
<div class="modal-content">
7+
<div class="modal-header">
8+
<h5 class="modal-title">Settings</h5>
9+
<button class="close" type="button" data-dismiss="modal" aria-label="Close">
10+
<span aria-hidden="true">&times;</span>
11+
</button>
12+
</div>
13+
<div class="modal-body">
14+
<div class="container-fluid">
15+
<div class="row">
16+
<div class="col-12">
17+
<div class="settings-obj">
18+
<div class="alert" ng-class="vm.settings.gitExists.err ? 'failed-setting alert-danger' : 'alert-success'">{{vm.settings.gitExists.err ? vm.settings.gitExists.msg : 'Yay! I found GIT.'}}
19+
<span class="fix-this-error pull-right btn-link">Fix</span>
20+
</div>
21+
<div class="settings-obj-fix hidden" ng-if="vm.settings.gitExists.err">
22+
<form class="form-inline">
23+
<div class="form-group mx-sm-3 mb-2">
24+
<label for="git-exec-path" class="">Path to GIT executible:&nbsp;</label>
25+
<input type="text" class="form-control" ng-model="vm.settings.gitExists.path" id="git-exec-path" placeholder="/usr/local/bin OR C:/Program Files/Git">
26+
</div>
27+
<button ng-click="vm.saveGitExecutablePath()" class="btn btn-primary mb-2">Save and Recheck</button>
28+
</form>
29+
</div>
30+
</div>
31+
</div>
32+
</div>
33+
</div>
34+
</div>
35+
</div>
36+
</div>
37+
</div>

public/js/app/webgit-home/repo-detail/repo-detail.component.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// TODO: Handle error codes.
22
(function() {
3-
var repoDetailModule = angular.module('RepoDetailModule', ['ngRoute']);
3+
var repoDetailModule = angular.module('RepoDetailModule', ['ngRoute', 'WebgitHomeModule']);
44
var repoName = null;
55
var $commitModal = null;
66
var $pushModal = null;

public/js/app/webgit-home/repo-detail/repo-detail.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<button class="btn btn-secondary" title="Open Pull Dialog" ng-click="vm.showPullDialog()"><i class="fa fa-arrow-down" aria-hidden="true"></i> Pull...</button>
77
<button class="btn btn-secondary" title="Open Push Dialog" ng-click="vm.showPushDialog()"><i class="fa fa-arrow-up" aria-hidden="true"></i> Push...</button>
88
<button class="btn btn-secondary" title="Open Stash Dialog" ng-click="vm.showStashDialog()"><i class="fa fa-database"></i> Stash...</button>
9-
9+
<check-settings show-on-error-only="true"></check-settings>
1010
<div id="log-search-container" class="pull-right">
1111
<div class="input-group">
1212
<div class="input-group-prepend">

public/js/app/webgit-home/webgit-home.component.js

Lines changed: 3 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
var $responseModal = $('#response-modal');
1212
var $responseModalTitle = $responseModal.find('#response-title');
1313
var $responseModalBody = $responseModal.find('#response-body');
14-
var $settingsModal = $('#settings-modal');
14+
1515

1616
$responseModal.on('hide.bs.modal', function(e) {
1717
$responseModalBody.html('');
@@ -25,66 +25,14 @@
2525
vm.openAfterCheckingOut = true;
2626
vm.testGit = testGit;
2727
vm.getRepoTitle = getRepoTitle;
28-
vm.viewSettingsModal = viewSettingsModal;
29-
30-
vm.saveGitExecutablePath = saveGitExecutablePath;
3128

3229
WebgitHomeService.getClonedRepos().then(function(data) {
3330
var allRepos = data.allRepos;
3431
vm.clonedRepos = allRepos;
3532
});
36-
37-
resetSettings();
38-
bindEvents();
39-
33+
4034
return;
4135

42-
function resetSettings() {
43-
vm.settings = {
44-
gitExists: {}
45-
};
46-
}
47-
48-
function saveGitExecutablePath() {
49-
// save vm.settings.gitExists to local storage. rescan for settings.
50-
localStorage.setItem('gitonbrowser.gitPath', vm.settings.gitExists.path);
51-
validateSettings();
52-
}
53-
54-
function bindEvents() {
55-
$('.settings-obj').on('click', '.fix-this-error', function(e) {
56-
var $settingsObj = $(e.delegateTarget);
57-
$settingsObj.find('.settings-obj-fix').toggleClass('hidden');
58-
});
59-
}
60-
61-
function viewSettingsModal() {
62-
$settingsModal.modal('show');
63-
return validateSettings();
64-
}
65-
66-
function validateSettings() {
67-
resetSettings();
68-
var options = {};
69-
var gitExecutablePath = localStorage.getItem('gitonbrowser.gitPath');
70-
if(gitExecutablePath) {
71-
options.gitExecutablePath = gitExecutablePath;
72-
}
73-
return WebgitHomeService.getSettings(options).then(function(d) {
74-
if(d.errorCode) {
75-
switch(d.errorCode) {
76-
case 1: {
77-
// git not found.
78-
vm.settings.gitExists.err = 1;
79-
vm.settings.gitExists.msg = d.msg;
80-
vm.settings.gitExists.description = d.description;
81-
break;
82-
}
83-
}
84-
}
85-
});
86-
}
87-
8836
function getRepoTitle(path) {
8937
return utils.decodePath(path);
9038
}
@@ -130,16 +78,10 @@
13078
this.browseRepo = browseRepo;
13179
this.clone = clone;
13280
this.testGit = testGit;
133-
this.getSettings = getSettings;
81+
13482

13583
return;
13684

137-
function getSettings(options) {
138-
return $http.post('/settings', options).then(function(res) {
139-
return res.data;
140-
});
141-
}
142-
14385
function clone(pathOfRepo, pathOfDestination, subdirName) {
14486
return $http.post('/clonerepo', {
14587
url: window.encodeURIComponent(pathOfRepo),

public/js/app/webgit-home/webgit-home.css

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,4 @@
88

99
.home-card {
1010
margin-top: 30px;
11-
}
12-
13-
.home-settings-icon {
14-
cursor: pointer;
15-
color: #007bff;
16-
}
17-
18-
.home-settings-icon:hover {
19-
color: #6c757d;
20-
}
21-
22-
.home-settings-icon.has-error {
23-
color: #dc3545;
24-
}
25-
26-
.settings-obj .fix-this-error {
27-
display: none;
28-
cursor: pointer;
29-
}
30-
31-
.settings-obj .failed-setting .fix-this-error {
32-
display: block;
33-
}
34-
35-
.settings-obj-fix.hidden {
36-
display: none;
3711
}

public/js/app/webgit-home/webgit-home.html

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<link href="/js/app/webgit-home/webgit-home.css" rel="stylesheet" />
33
<div class="row">
44
<div class="col-12">
5-
<h1 class="main-title">gitonbrowser <span ng-click="vm.viewSettingsModal()" class="fa fa-gear home-settings-icon"></span></h1>
5+
<h1 class="main-title">gitonbrowser <check-settings></check-settings></h1>
66
</div>
77
</div>
88
<div class="row">
@@ -50,36 +50,6 @@ <h4 class="card-header">Browse cloned repository</h4>
5050
</div>
5151
</div>
5252
</div>
53-
<div class="modal fade" id="settings-modal" tabindex="-1" role="dialog">
54-
<div class="modal-dialog modal-lg" role="document">
55-
<div class="modal-content">
56-
<div class="modal-header">
57-
<h5 class="modal-title">Settings</h5>
58-
<button class="close" type="button" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
59-
</div>
60-
<div class="modal-body">
61-
<div class="container-fluid">
62-
<div class="row">
63-
<div class="col-12">
64-
<div class="settings-obj">
65-
<div class="alert" ng-class="vm.settings.gitExists.err ? 'failed-setting alert-danger' : 'alert-success'">{{vm.settings.gitExists.err ? vm.settings.gitExists.msg : 'Yay! I found GIT.'}}<span class="fix-this-error pull-right btn-link">Fix</span></div>
66-
<div class="settings-obj-fix hidden" ng-if="vm.settings.gitExists.err">
67-
<form class="form-inline">
68-
<div class="form-group mx-sm-3 mb-2">
69-
<label for="git-exec-path" class="">Path to GIT executible:&nbsp;</label>
70-
<input type="text" class="form-control" ng-model="vm.settings.gitExists.path" id="git-exec-path" placeholder="/usr/local/bin OR C:/Program Files/Git">
71-
</div>
72-
<button ng-click="vm.saveGitExecutablePath()" class="btn btn-primary mb-2">Save and Recheck</button>
73-
</form>
74-
</div>
75-
</div>
76-
</div>
77-
</div>
78-
</div>
79-
</div>
80-
</div>
81-
</div>
82-
</div>
8353
<div class="modal fade" id="clone-modal" tabindex="-1" role="dialog">
8454
<div class="modal-dialog modal-lg" role="document">
8555
<div class="modal-content">

views/layout.jade

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,6 @@ html
3434
script(src='/js/app/app.config.js')
3535
script(src='/js/app/utils.service.js')
3636
script(src='/js/app/webgit-home/webgit-home.component.js')
37+
script(src='/js/app/webgit-home/check-settings/check-settings.component.js')
3738
script(src='/js/app/webgit-home/repositories.component.js')
3839
script(src='/js/app/webgit-home/repo-detail/repo-detail.component.js')

0 commit comments

Comments
 (0)