Browse Source

Page re-works. Sidebar

Nathaniel van Diepen 10 years ago
parent
commit
d285a88e60

+ 11 - 0
api.php

@@ -49,6 +49,7 @@
 						'type'=>'pages',
 						'name'=>'issue'
 					);
+					$ret['topbar'] = 'back';
 					if($context = issueObj($id)){
 						$context['user'] = userObj($context['user']);
 						if($LOGGEDIN){
@@ -69,6 +70,7 @@
 						'type'=>'pages',
 						'name'=>'scrum'
 					);
+					$ret['topbar'] = 'back';
 					if($context = scrumObj($id)){
 						$context['user'] = userObj($context['user']);
 						if($LOGGEDIN){
@@ -89,6 +91,7 @@
 						'type'=>'pages',
 						'name'=>'project'
 					);
+					$ret['topbar'] = 'back';
 					if($context = projectObj($id)){
 						$context['user'] = userObj($context['user']);
 						if($LOGGEDIN){
@@ -181,6 +184,14 @@
 												}
 											}
 										break;
+										case 'latest':
+											if($res = query("SELECT i.id,i.title,i.description,u.name as user,s.name as status,p.name as priority,p.color FROM `issues` i JOIN `users` u ON u.id = i.u_id LEFT JOIN `statuses` s ON s.id = i.st_id LEFT JOIN `priorities` p ON p.id = i.pr_id LIMIT 10")){
+												$context['issues'] = fetch_all($res,MYSQLI_ASSOC);
+												foreach($context['issues'] as $key => $issue){
+													$context['issues'][$key]['user'] = userObj($issue['user']);
+												}
+											}
+										break;
 									}
 								}
 							}

+ 5 - 0
data/pages/index.options

@@ -0,0 +1,5 @@
+{
+	"context": [
+		"latest"
+	]
+}

+ 24 - 9
data/pages/index.template

@@ -34,15 +34,30 @@
 	Bugs is a project issue tracker.
 </p>
 {{#if key}}
-	<a class="button" href="#page-projects">
-		Projects
-	</a>
-	<a class="button" href="#page-issues">
-		Issues
-	</a>
-	<a class="button" href="#page-users">
-		Users
-	</a>
+	<div>
+		<section data-type="list">
+			<header>
+				Latest Issues
+			</header>
+			<ul>
+				{{#each issues}}
+					<li>
+						<aside class="pack-end">
+							{{user.name}}
+						</aside>
+						<a href="#!{{id}}">
+							<p>
+								{{#if priority}}[<span style="{{#if color}}color:{{color}};{{/if}}">{{priority}}</span>] {{/if}}{{title}}{{#if status}} ({{status}}){{/if}}
+							</p>
+							<p>
+								{{description}}
+							</p>
+						</a>
+					</li>
+				{{/each}}
+			</ul>
+		</section>
+	</div>
 {{else}}
 	<a class="button" href="#page-register">
 		Register

+ 1 - 0
data/pages/issues.options

@@ -1,5 +1,6 @@
 {
 	"secure": true,
+	"topbar": "issues",
 	"context": [
 		"issues"
 	]

+ 23 - 21
data/pages/issues.template

@@ -1,22 +1,24 @@
-<a class="button" href="#page-newissue">
-	New
-</a>
-<div class="accordion">
-	<span class="icons">
-		{
-			"header": "ui-icon-wrench",
-			"activeHeader": "ui-icon-wrench"
-		}
-	</span>
-	{{#each issues}}
-		<h3>
-			{{#if priority}}[<span style="{{#if color}}color:{{color}};{{/if}}">{{priority}}</span>] {{/if}}{{title}}{{#if status}} ({{status}}){{/if}} - <small>{{user.name}}</small>
-			<a href="#!{{id}}" class="button">
-				Open
-			</a>
-		</h3>
-		<div>
-			{{description}}
-		</div>
-	{{/each}}
+<div>
+	<section data-type="list">
+		<header>
+			Issues
+		</header>
+		<ul>
+			{{#each issues}}
+				<li>
+					<aside class="pack-end">
+						{{user.name}}
+					</aside>
+					<a href="#!{{id}}">
+						<p>
+							{{#if priority}}[<span style="{{#if color}}color:{{color}};{{/if}}">{{priority}}</span>] {{/if}}{{title}}{{#if status}} ({{status}}){{/if}}
+						</p>
+						<p>
+							{{description}}
+						</p>
+					</a>
+				</li>
+			{{/each}}
+		</ul>
+	</section>
 </div>

+ 3 - 4
data/pages/messages.template

@@ -1,9 +1,8 @@
-<a class="button" href="#page-newmessage">
-	New
-</a>
 <div>
 	<section data-type="list">
-
+		<header>
+			Messages
+		</header>
 		<ul>
 			{{#each messages}}
 				<li>

+ 2 - 1
data/pages/newissue.options

@@ -1,4 +1,5 @@
 {
 	"title": "New Issue",
-	"secure": true
+	"secure": true,
+	"topbar": "back"
 }

+ 3 - 3
data/pages/newissue.template

@@ -7,8 +7,8 @@
 			<textarea type="text" name="description" class="fill-width" placeholder="Description"/></textarea>
 		</div>
 		<div>
-			<input type="button" value="cancel" class="cancel"/>
-			<input type="submit" value="create"/>
+			<button value="Cancel" class="danger">Cancel</button>
+			<button value="Create" onclick="$(this).parent().submit();">Create</button>
 		</div>
 	</form>
 	<script>
@@ -30,7 +30,7 @@
 					return false;
 				});
 				return false;
-			}).find('.cancel').click(function(){
+			}).find('.danger').click(function(){
 				back();
 				return false;
 			});

+ 2 - 1
data/pages/newmessage.options

@@ -2,5 +2,6 @@
 	"secure": true,
 	"context": [
 		"users"
-	]
+	],
+	"topbar": "back"
 }

+ 3 - 3
data/pages/newmessage.template

@@ -6,8 +6,8 @@
 		<textarea name="message" class="fill-width" placeholder="Message"/></textarea>
 	</div>
 	<div>
-		<input type="button" value="cancel" class="cancel"/>
-		<input type="submit" value="create"/>
+		<button value="Cancel" class="danger">Cancel</button>
+		<button value="Create" onclick="$(this).parent().submit();">Create</button>
 	</div>
 	<datalist id="users">
 		{{#each users}}
@@ -34,7 +34,7 @@
 				return false;
 			});
 			return false;
-		}).find('.cancel').click(function(){
+		}).find('.danger').click(function(){
 			back();
 			return false;
 		});

+ 2 - 1
data/pages/newproject.options

@@ -1,4 +1,5 @@
 {
 	"title": "New Project",
-	"secure": true
+	"secure": true,
+	"topbar": "back"
 }

+ 3 - 3
data/pages/newproject.template

@@ -7,8 +7,8 @@
 			<textarea type="text" name="description" class="fill-width" placeholder="Description"/></textarea>
 		</div>
 		<div>
-			<input type="button" value="cancel" class="cancel"/>
-			<input type="submit" value="create"/>
+			<button value="Cancel" class="danger">Cancel</button>
+			<button value="Create" onclick="$(this).parent().submit();">Create</button>
 		</div>
 	</form>
 	<script>
@@ -30,7 +30,7 @@
 					return false;
 				});
 				return false;
-			}).find('.cancel').click(function(){
+			}).find('.danger').click(function(){
 				back();
 				return false;
 			});

+ 6 - 0
data/pages/profile.template

@@ -0,0 +1,6 @@
+<div>
+	Name: {{user.name}}
+</div>
+<div>
+	Email: {{user.email}}
+</div>

+ 1 - 0
data/pages/projects.options

@@ -1,5 +1,6 @@
 {
 	"secure": true,
+	"topbar": "projects",
 	"context": [
 		"projects"
 	]

+ 23 - 21
data/pages/projects.template

@@ -1,22 +1,24 @@
-<a class="button" href="#page-newproject">
-	New
-</a>
-<div class="accordion">
-	<span class="icons">
-		{
-			"header": "ui-icon-wrench",
-			"activeHeader": "ui-icon-wrench"
-		}
-	</span>
-	{{#each projects}}
-		<h3>
-			{{title}} - <small>{{user.name}}</small>
-			<a href="#project-{{id}}" class="button">
-				Open
-			</a>
-		</h3>
-		<div>
-			{{description}}
-		</div>
-	{{/each}}
+<div>
+	<section data-type="list">
+		<header>
+			Projects
+		</header>
+		<ul>
+			{{#each projects}}
+				<li>
+					<aside class="pack-end">
+						{{user.name}}
+					</aside>
+					<a href="#project-{{id}}">
+						<p>
+							{{title}}
+						</p>
+						<p>
+							{{description}}
+						</p>
+					</a>
+				</li>
+			{{/each}}
+		</ul>
+	</section>
 </div>

+ 15 - 6
data/pages/users.template

@@ -1,6 +1,15 @@
-{{#each users}}
-	<a class="button align-left" style="" href="#~{{name}}">
-		<div style="float: left;background-image:url(img/headers/icons/user.png);width:20px;height:20px;background-size:20px;"></div>
-		{{name}}
-	</a>
-{{/each}}
+<div>
+	<section data-type="list">
+		<ul>
+			{{#each users}}
+				<li>
+					<a href="#~{{name}}">
+						<p>
+							{{name}}
+						</p>
+					</a>
+				</li>
+			{{/each}}
+		</ul>
+	</section>
+</div>

+ 57 - 1
data/sidebars/default.template

@@ -1 +1,57 @@
- 
+<header>
+	<menu type="toolbar">
+		<a id="toolbar-done">
+			Done
+		</a>
+	</menu>
+	<h1>
+		Bugs
+	</h1>
+</header>
+<nav>
+	<h2>
+		Pages
+	</h2>
+	<ul>
+		<li>
+			<a href="#page-index">
+				Home
+			</a>
+		</li>
+		<li>
+			<a href="#page-projects">
+				Projects
+			</a>
+		</li>
+		<li>
+			<a href="#page-issues">
+				Issues
+			</a>
+		</li>
+		<li>
+			<a href="#page-users">
+				Users
+			</a>
+		</li>
+	</ul>
+	<h2>
+		{{user.name}}
+	</h2>
+	<ul>
+		<li>
+			<a href="#page-profile">
+				Profile
+			</a>
+		</li>
+		<li>
+			<a href="#page-messages">
+				Messages
+			</a>
+		</li>
+		<li>
+			<a href="#page-logout">
+				Logout
+			</a>
+		</li>
+	</ul>
+</nav>

+ 5 - 0
data/topbars/issues.options

@@ -0,0 +1,5 @@
+{
+	"actions":{
+		"new": "page-newissue"
+	}
+}

+ 25 - 0
data/topbars/issues.template

@@ -0,0 +1,25 @@
+<a>
+	<span class="icon icon-menu">
+		hide sidebar
+	</span>
+</a>
+<a>
+	<span class="icon icon-menu">
+		show sidebar
+	</span>
+</a>
+<menu type="toolbar">
+	<a>
+		<span class="icon icon-edit">
+			edit
+		</span>
+	</a>
+	<a>
+		<span class="icon icon-add">
+			add
+		</span>
+	</a>
+</menu>
+<h1>
+	{{title}}
+</h1>

+ 5 - 0
data/topbars/messages.options

@@ -0,0 +1,5 @@
+{
+	"actions":{
+		"new": "page-newmessage"
+	}
+}

+ 8 - 3
data/topbars/messages.template

@@ -1,6 +1,11 @@
-<a id="btn-lists-back">
-	<span class="icon icon-back">
-		back
+<a>
+	<span class="icon icon-menu">
+		hide sidebar
+	</span>
+</a>
+<a>
+	<span class="icon icon-menu">
+		show sidebar
 	</span>
 </a>
 <menu type="toolbar">

+ 5 - 0
data/topbars/projects.options

@@ -0,0 +1,5 @@
+{
+	"actions":{
+		"new": "page-newproject"
+	}
+}

+ 25 - 0
data/topbars/projects.template

@@ -0,0 +1,25 @@
+<a>
+	<span class="icon icon-menu">
+		hide sidebar
+	</span>
+</a>
+<a>
+	<span class="icon icon-menu">
+		show sidebar
+	</span>
+</a>
+<menu type="toolbar">
+	<a>
+		<span class="icon icon-edit">
+			edit
+		</span>
+	</a>
+	<a>
+		<span class="icon icon-add">
+			add
+		</span>
+	</a>
+</menu>
+<h1>
+	{{title}}
+</h1>

+ 1 - 4
index.php

@@ -150,10 +150,7 @@
 	</head>
 	<body lang="en" role="application">
 		<section id="index" data-position="current">
-			<section data-type="sidebar" style="display:none;">
-				<header></header>
-				<nav></nav>
-			</section>
+			<section id="sidebar" data-type="sidebar"></section>
 			<section id="drawer" role="region">
 				<header class="fixed" id="topbar">
 				</header>

+ 68 - 48
js/index.js

@@ -4,6 +4,7 @@
 		Old = {},
 		Key = null,
 		flags = [],
+		actions = [],
 		templates = [],
 		flag = window.flag = function(name,value){
 			if(exists(value)){
@@ -49,6 +50,11 @@
 			}
 			return false;
 		},
+		action = window.action = function(name){
+			if(exists(actions[name])){
+				loadState(actions[name]);
+			}
+		},
 		template = window.template = function(type,name,template,hash){
 			var id = (function(type,name){
 					for(var i in templates){
@@ -250,7 +256,16 @@
 										console.log('Context detected console.logout');
 										setKey(null);
 									}
-									render.topbar(template('topbars',d.topbar.template),d.topbar.context);
+									actions = [];
+									if(exists(d.topbar)){
+										render.topbar(template('topbars',d.topbar.template),d.topbar.context);
+										if(exists(d.topbar.context.actions)){
+											actions = d.topbar.context.actions;
+										}
+									}
+									if(exists(d.sidebar)){
+										render.sidebar(template('sidebars',d.sidebar.template),d.sidebar.context);
+									}
 									if(exists(d.template)){
 										console.log('Using template: '+d.template.type+':'+d.template.name);
 										d.template = template(d.template.type,d.template.name);
@@ -310,6 +325,7 @@
 				$('#topbar .icon-back').click(function(){
 					back();
 				});
+				$('#topbar h1').text($('#topbar h1').text().capitalize());
 				$('#topbar .icon-menu').click(function(){
 					if($('#drawer').hasClass('open')){
 						$('#drawer').removeClass('open').css('transform','');
@@ -317,10 +333,22 @@
 						$('#drawer').addClass('open').css('transform','translateX(80%)');
 					}
 				});
-				$('#topbar .icon-new').click(function(){
+				$('#topbar .icon-add').click(function(){
 					action('new');
 				});
-				//render.refresh('#topbar');
+				render.links('#topbar');
+			},
+			sidebar: function(t,c){
+				$('#sidebar').html(Handlebars.compile(t)(c));
+				$('#toolbar-done').click(function(){
+					$('#drawer').removeClass('open').css('transform','');
+				});
+				render.links('#sidebar');
+				$('#sidebar').find('a').click(function(e){
+					$('#drawer').removeClass('open').css('transform','');
+					e.preventDefault();
+					return false;
+				});
 			},
 			content: function(t,c){
 				$(document).unbind('ready');
@@ -483,38 +511,38 @@
 				render.inputs(selector);
 			},
 			inputs: function(selector){
-				// $(selector).find('input[type=text],input[type=password]').each(function(){
-				// 	var input = $(this),
-				// 		height = input.height()>=17?17:input.height();
-				// 	input.siblings('.input-clear').remove();
-				// 	input.off('focus').off('blur').after(
-				// 		$('<div>').css({
-				// 			position: 'absolute',
-				// 			right: $(window).width() - (input.outerWidth() + input.position().left)+2,
-				// 			top: input.position().top+2,
-				// 			'background-image': 'url(img/headers/icons/clear.png)',
-				// 			'background-position': 'center',
-				// 			'background-size': height+'px '+height+'px',
-				// 			'background-repeat': 'no-repeat',
-				// 			width: input.height(),
-				// 			height: input.height(),
-				// 			cursor: 'pointer'
-				// 		}).hide().addClass('input-clear').mousedown(function(){
-				// 			input.val('');
-				// 		})
-				// 	);
-				// 	input.focus(function(){
-				// 		input.next().show();
-				// 	}).blur(function(e){
-				// 		input.next().hide();
-				// 	});
-				// });
-				// $(selector).find('input[type=text],input[type=password],textarea').each(function(){
-				// 	var input = $(this);
-				// 	if(input.hasClass('fill-width')){
-				// 		input.css('width','calc(100% - '+(input.outerWidth()-input.width())+'px)');
-				// 	}
-				// });
+				/*$(selector).find('input[type=text],input[type=password]').each(function(){
+					var input = $(this),
+						height = input.height()>=17?17:input.height();
+					input.siblings('.input-clear').remove();
+					input.off('focus').off('blur').after(
+						$('<div>').css({
+							position: 'absolute',
+							right: $(window).width() - (input.outerWidth() + input.position().left)+2,
+							top: input.position().top+2,
+							'background-image': 'url(img/headers/icons/clear.png)',
+							'background-position': 'center',
+							'background-size': height+'px '+height+'px',
+							'background-repeat': 'no-repeat',
+							width: input.height(),
+							height: input.height(),
+							cursor: 'pointer'
+						}).hide().addClass('input-clear').mousedown(function(){
+							input.val('');
+						})
+					);
+					input.focus(function(){
+						input.next().show();
+					}).blur(function(e){
+						input.next().hide();
+					});
+				});
+				$(selector).find('input[type=text],input[type=password],textarea').each(function(){
+					var input = $(this);
+					if(input.hasClass('fill-width')){
+						input.css('width','calc(100% - '+(input.outerWidth()-input.width())+'px)');
+					}
+				});*/
 			},
 			dialog: function(selector,title){
 				$(selector).dialog({
@@ -547,17 +575,7 @@
 						href = href.substr(href.indexOf('#')+1);
 						$(this).click(function(e){
 							try{
-								if(($(this).hasClass('topbar-home') || $(this).hasClass('topbar-back'))&&$(window).width()<767){
-									$('#topbar').children('div.topbar-right,div.topbar-left').toggle();
-									$('#topbar').toggleClass('overflow-hide');
-									$(window).resize();
-								}else if($(this).hasClass('topbar-history')){
-									back();
-								}else if($(this).hasClass('topbar-current')){
-									replaceState(href);
-								}else{
-									loadState(href);
-								}
+								loadState(href);
 							}catch(error){
 								console.error(error);
 							}
@@ -739,8 +757,10 @@
 				},'json');
 			};
 			fn('topbars',function(){
-				fn('pages',function(){
-					callback();
+				fn('sidebars',function(){
+					fn('pages',function(){
+						callback();
+					});
 				});
 			});
 		};

+ 16 - 0
php/functions.php

@@ -57,6 +57,12 @@
 		}else{
 			$context = array();
 		}
+		if(file_exists(PATH_DATA.'topbars/'.$id.'.options')){
+			$options = objectToarray(json_decode(file_get_contents(PATH_DATA.'topbars/'.$id.'.options'),true));
+			foreach($options as $key => $option){
+				$context[$key] = $option;
+			}
+		}
 		$context['title'] = $title;
 		if(!isset($_GET['no_state'])){
 			$context['url'] = $url;
@@ -70,6 +76,16 @@
 			'template'=>$topbar,
 			'context'=>$context
 		);
+		// Sidebar
+		if(isset($json['sidebar'])){
+			$sidebar = $json['sidebar'];
+		}else{
+			$sidebar = 'default';
+		}
+		$json['sidebar'] = array(
+			'template'=>$sidebar,
+			'context'=>$context
+		);
 		header('Content-type: application/json');
 		die(json_encode($json));
 	}