Skip to content

Commit 0b6ec72

Browse files
committed
Refactored some code
1 parent e380a80 commit 0b6ec72

File tree

5 files changed

+106
-83
lines changed

5 files changed

+106
-83
lines changed

OpenNote/index.html

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -64,45 +64,10 @@
6464

6565
</head>
6666
<body>
67-
<div id="menu" class="ng-hide fadeIn" ng-show="showMenu">
68-
<div class="navbar-header">
69-
<div class="left">
70-
<button type="button" class="customButton" id="home" onclick="window.location.href='#/folder';" data-intro="{{helpContent.homeButton}}">Notes</button>
71-
</div>
72-
<div class="right">
73-
<button type="button" class="navbar-toggle noPadding noMargin" data-toggle="collapse" data-target=".navbar-collapse">
74-
Options
75-
</button>
76-
</div>
77-
</div>
78-
<div class="navbar-collapse collapse noShadow">
79-
<ul class="nav navbar-nav navbar-right">
80-
<li ng-repeat="button in buttons">
81-
<button type="button" class="customButton" ng-click="button.action();" data-intro="{{button.helpText}}">{{button.text}}</button>
82-
</li>
83-
<li ng-show="showHelpButton">
84-
<button type="button" class="customButton" onclick="introJs().start();">Help</button>
85-
</li>
86-
<li ng-show="showLogOutButton">
87-
<button type="button" class="customButton" ng-click="logOut();">Log out</button>
88-
</li>
89-
</ul>
90-
</div>
91-
</div>
67+
<div id="menu" class="ng-hide fadeIn" ng-show="showMenu" ng-include="'openNote/partials/navBarPartial.html'"></div>
9268

93-
<div class="col-lg-2 col-md-3 col-sm-4">
94-
<div id="sideBar" class="ng-hide noPadding fadeIn" ng-controller="listController" ng-show="showSideBar" data-intro="{{helpContent.listArea}}">
95-
<div id="folderList">
96-
<div ui-tree="options" id="tree-root">
97-
<ol ui-tree-nodes="" ng-model="data.foldersInside" >
98-
<li ng-repeat="folder in data.foldersInside" ui-tree-node ng-include="'openNote/partials/treePartial.html'" data-collapsed="!node.collapsed"></li>
99-
</ol>
100-
</div>
101-
</div>
102-
</div>
103-
</div>
69+
<div class="col-lg-2 col-md-3 col-sm-4" ng-include="'openNote/partials/listPartial.html'"></div>
10470

105-
<div class="col-lg-10 col-md-9 col-sm-8" ng-view data-intro="{{helpContent.viewArea}}">
106-
</div>
71+
<div class="col-lg-10 col-md-9 col-sm-8" ng-view data-intro="{{helpContent.viewArea}}"> </div>
10772
</body>
10873
</html>

OpenNote/openNote/openNote.js

Lines changed: 69 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,22 @@
44
*/
55

66
//Module Declaration
7-
var openNote = angular.module("openNote", ["ngRoute","ngResource", "ngSanitize", "ngAnimate", "ui.tree"]);
7+
var openNote = angular.module("openNote", [ "ngRoute",
8+
"ngResource",
9+
"ngSanitize",
10+
"ngAnimate",
11+
"ui.tree"]);
812

913
/**
1014
* Used to redirect users to login if their token has expired
1115
* Runs on every route
1216
*/
13-
openNote.run(function ($rootScope, $location, userService, config, serverConfigService, $http){
17+
openNote.run(function ( $rootScope,
18+
$location,
19+
userService,
20+
config,
21+
serverConfigService,
22+
$http){
1423
$rootScope.$on("$routeChangeStart", function (event) {
1524
//server config values
1625
serverConfigService.getConfig().then(function(config){
@@ -20,47 +29,64 @@ openNote.run(function ($rootScope, $location, userService, config, serverConfigS
2029
$rootScope.serverConfig=config;
2130
}); //attach server config to root scope
2231

23-
/**
24-
* Initial entry if not logged in
25-
*/
26-
if (!userService.hasValidToken()&&$location.path()!="/") {
27-
event.preventDefault();
28-
$location.path("/");
29-
}
30-
else{
32+
if (isLoggedInOrIsOnLoginScreen())//Initial entry if not logged in
33+
forceLogin();
34+
else//Initial entry after if logged in
35+
if($location.path()!="/" && !$rootScope.showMenu && !$rootScope.showSideBar)//make sure we only fade in/run once
36+
$rootScope.$emit("init");
37+
38+
});
39+
40+
/**
41+
* Check to see if user is logged in or on the login screen
42+
*/
43+
var isLoggedInOrIsOnLoginScreen = function(){
44+
return !userService.hasValidToken()&&$location.path()!="/";
45+
}
46+
47+
/**
48+
* Force user to login
49+
*/
50+
var forceLogin = function(){
51+
event.preventDefault();
52+
$location.path("/");
53+
}
54+
55+
/**
56+
* Initialize app and start fade in
57+
*/
58+
$rootScope.$on("init",function(){
59+
userService.useAPITokenHeader();//use token
60+
61+
$rootScope.$on("$viewContentLoaded",function(){//wait for page to load before requesting list view
62+
$rootScope.$emit("reloadListView"); //send an event to tell the list view to reload
63+
});
64+
65+
$rootScope.showMenu=true;
66+
$rootScope.showSideBar=true;
67+
68+
//options for humans
69+
$rootScope.helpContent=config.getHelpContent();
70+
71+
$rootScope.showHelpButton = config.showHelpButton();
72+
$rootScope.showLogOutButton = config.showLogOutButton();
73+
3174
/**
32-
* Initial entry after if logged in
75+
* Log out function
3376
*/
34-
if($location.path()!="/" && !$rootScope.showMenu && !$rootScope.showSideBar){//make sure we only fade in/run once
35-
userService.useAPITokenHeader();//use token
36-
$rootScope.$emit("reloadListView", {}); //send and event to tell the list view to reload
37-
$rootScope.showMenu=true;
38-
$rootScope.showSideBar=true;
39-
40-
//options for humans
41-
$rootScope.helpContent=config.getHelpContent();
42-
43-
$rootScope.showHelpButton = config.showHelpButton();
44-
$rootScope.showLogOutButton = config.showLogOutButton();
45-
46-
/**
47-
* Log out function
48-
*/
49-
$rootScope.logOut = function(){
50-
userService.destroyTokenHeader();
51-
window.location.href='#/';
52-
$rootScope.showMenu=false;
53-
$rootScope.showSideBar=false;
54-
}
55-
56-
//Check for updates
57-
$http.get(config.getUpdateURL()).then(
58-
function(response){//Successful
59-
if(response.data.version!=config.getVersion())
60-
alertify.log("<a href='"+response.data.updateURL+"' target='_blank'>"+response.data.updateText+"</a>", "", 0);
61-
}
62-
);
63-
}
64-
}
65-
});
77+
$rootScope.logOut = function(){
78+
userService.destroyTokenHeader();
79+
window.location.href='#/';
80+
$rootScope.showMenu=false;
81+
$rootScope.showSideBar=false;
82+
}
83+
84+
//Check for updates
85+
$http.get(config.getUpdateURL()).then(
86+
function(response){//Successful
87+
if(response.data.version!=config.getVersion())
88+
alertify.log("<a href='"+response.data.updateURL+"' target='_blank'>"+response.data.updateText+"</a>", "", 0);
89+
}
90+
);
91+
})
6692
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<div id="sideBar" class="ng-hide noPadding fadeIn" ng-controller="listController" ng-show="showSideBar" data-intro="{{helpContent.listArea}}">
2+
<div id="folderList">
3+
<div ui-tree="options" id="tree-root">
4+
<ol ui-tree-nodes="" ng-model="data.foldersInside" >
5+
<li ng-repeat="folder in data.foldersInside" ui-tree-node ng-include="'openNote/partials/treePartial.html'" data-collapsed="!node.collapsed"></li>
6+
</ol>
7+
</div>
8+
</div>
9+
</div>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<div class="navbar-header">
2+
<div class="left">
3+
<button type="button" class="customButton" id="home" onclick="window.location.href='#/folder';" data-intro="{{helpContent.homeButton}}">Notes</button>
4+
</div>
5+
<div class="right">
6+
<button type="button" class="navbar-toggle noPadding noMargin" data-toggle="collapse" data-target=".navbar-collapse">
7+
Options
8+
</button>
9+
</div>
10+
</div>
11+
<div class="navbar-collapse collapse noShadow">
12+
<ul class="nav navbar-nav navbar-right">
13+
<li ng-repeat="button in buttons">
14+
<button type="button" class="customButton" ng-click="button.action();" data-intro="{{button.helpText}}">{{button.text}}</button>
15+
</li>
16+
<li ng-show="showHelpButton">
17+
<button type="button" class="customButton" onclick="introJs().start();">Help</button>
18+
</li>
19+
<li ng-show="showLogOutButton">
20+
<button type="button" class="customButton" ng-click="logOut();">Log out</button>
21+
</li>
22+
</ul>
23+
</div>

OpenNote/openNote/style/animations.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
.fadeIn.ng-hide-remove,
44
.fadeIn.ng-enter,
55
.fadeIn.ng-leave{
6-
transition:all linear 2s;
7-
display: block !important;
6+
transition:all 2s;
7+
display: block;
88
}
99

1010
.fadeIn.ng-hide-add.ng-hide-add-active,

0 commit comments

Comments
 (0)