Browse Source

Status/priority changing/logging

Nathaniel van Diepen 10 years ago
parent
commit
eb2bc80e57
5 changed files with 182 additions and 39 deletions
  1. 54 35
      api.php
  2. 87 3
      data/pages/issue.template
  3. 0 1
      index.php
  4. 1 0
      js/index.js
  5. 40 0
      php/issue.php

+ 54 - 35
api.php

@@ -347,43 +347,62 @@
 							break;
 							case 'issue':
 								back(true);
-								$ret['state'] = array(
-									'data'=>array(
-										'type'=>'page',
-										'id'=>$id,
-									)
-								);
-								if(isset($_GET['pid'])){
-									$ret['error'] = 'Invalid Action';
-								}elseif(is_valid('title')&&is_valid('description')){
-									if($id = newIssue($_GET['title'],$_GET['description'])){
-										sendMailAll('newissue','New Issue - '.$_GET['title'],array(
-											'title'=>$_GET['title'],
-											'url'=>'http://'.$_SERVER['HTTP_HOST'],
-											'id'=>$id
-										));
-									}else{
-										$ret['error'] = 'Unable to create issue. '.get_sql()->error;
-									}
-								}else{
-									$ret['error'] = 'Fill in all the details.';
-								}
-								retj($ret,$id);
-							break;
-							case 'message':
-								back(true);
-								if(isset($_GET['to'])&&isset($_GET['message'])){
-									if($uid = userId($_GET['to'])){
-										if(!personal_message($uid,$_GET['message'])){
-											$ret['error'] = 'Could not send message';
+								switch($_GET['action']){
+									case 'status':
+										if(!setStatus($_GET['issue'],$_GET['status'])){
+											$ret['error'] = 'Could not update status.';
+										}else{
+											alog('i',$_GET['issue'],'Status changed to '.statusName($_GET['status']));
 										}
-									}else{
-										$ret['error'] = "That user doesn't exist";
-									}
-								}else{
-									$ret['error'] = 'Empty details';
+										retj($ret);
+									break;
+									case 'priority':
+										if(!setPriority($_GET['issue'],$_GET['priority'])){
+											$ret['error'] = 'Could not update priority.';
+										}else{
+											alog('i',$_GET['issue'],'Priority changed to '.priorityName($_GET['priority']));
+										}
+										retj($ret);
+									break;
+									default:
+										$ret['state'] = array(
+											'data'=>array(
+												'type'=>'page',
+												'id'=>$id,
+											)
+										);
+										if(isset($_GET['pid'])){
+											$ret['error'] = 'Invalid Action';
+										}elseif(is_valid('title')&&is_valid('description')){
+											if($id = newIssue($_GET['title'],$_GET['description'])){
+												sendMailAll('newissue','New Issue - '.$_GET['title'],array(
+													'title'=>$_GET['title'],
+													'url'=>'http://'.$_SERVER['HTTP_HOST'],
+													'id'=>$id
+												));
+											}else{
+												$ret['error'] = 'Unable to create issue. '.get_sql()->error;
+											}
+										}else{
+											$ret['error'] = 'Fill in all the details.';
+										}
+										retj($ret,$id);
+									break;
+									case 'message':
+										back(true);
+										if(isset($_GET['to'])&&isset($_GET['message'])){
+											if($uid = userId($_GET['to'])){
+												if(!personal_message($uid,$_GET['message'])){
+													$ret['error'] = 'Could not send message';
+												}
+											}else{
+												$ret['error'] = "That user doesn't exist";
+											}
+										}else{
+											$ret['error'] = 'Empty details';
+										}
+										retj($ret,$id);
 								}
-								retj($ret,$id);
 							break;
 							case 'notifications':
 								if($LOGGEDIN){

+ 87 - 3
data/pages/issue.template

@@ -5,10 +5,30 @@
 	Description: {{description}}
 </div>
 <div>
-	Priority: <span style="{{#if color}}color:{{color}};{{/if}}">{{priority}}</span>
+	Priority:
+	<select name="priority">
+		<option style="background-color:white;">
+			(none)
+		</option>
+		{{#each priorities}}
+			<option style="background-color:{{color}};" value="{{id}}">
+				{{name}}
+			</option>
+		{{/each}}
+	</select>
 </div>
 <div>
-	Status: {{status}}
+	Status:
+	<select name="status">
+		<option style="background-color:white;">
+			(none)
+		</option>
+		{{#each statuses}}
+			<option value="{{id}}">
+				{{name}}
+			</option>
+		{{/each}}
+	</select>
 </div>
 <span style="font-size:small;">
 	Comments
@@ -35,4 +55,68 @@
 		"type": "issue",
 		"title": "Comment"
 	}
-</a>
+</a>
+<script>
+	(function(){
+		var status = false,
+			priority = false;
+		$('select[name=status]').change(function(){
+			var t = $(this);
+			if(status != t.val()){
+				apiCall({
+					type: 'action',
+					id: 'issue',
+					action: 'status',
+					status: t.val(),
+					issue: {{id}}
+				},function(d){
+					if(!d.error){
+						status = t.val();
+					}else{
+						alert(d.error);
+					}
+				});
+			}
+		}).children('option').each(function(){
+			if($(this).text().trim() == '{{status}}'){
+				$(this).prop('selected',true);
+				status = $(this).val();
+				$(this).parent().css(
+					'background-color',
+					this.style.backgroundColor
+				);
+			}
+		});
+		$('select[name=priority]').change(function(){
+			var t = $(this);
+			t.css(
+				'background-color',
+				t.children('option:selected').get(0).style.backgroundColor
+			);
+			if(priority != t.val()){
+				apiCall({
+					type: 'action',
+					id: 'issue',
+					action: 'priority',
+					priority: t.val(),
+					issue: {{id}}
+				},function(d){
+					if(!d.error){
+						priority = t.val();
+					}else{
+						alert(d.error);
+					}
+				});
+			}
+		}).children('option').each(function(){
+			if($(this).text().trim() == '{{priority}}'){
+				$(this).prop('selected',true);
+				priority = $(this).val();
+				$(this).parent().css(
+					'background-color',
+					this.style.backgroundColor
+				);
+			}
+		});
+	})();
+</script>

+ 0 - 1
index.php

@@ -135,7 +135,6 @@
 					window.screen.lockOrientation('portrait');
 				}
 			})(window,Modernizr);
-			Screen.lockOrientation();
 		</script>
 		<style>
 			@viewport{

+ 1 - 0
js/index.js

@@ -137,6 +137,7 @@
 							callback(d);
 						}catch(e){
 							error(e);
+							console.log(callback+'');
 						}
 					}
 				},'json');

+ 40 - 0
php/issue.php

@@ -9,6 +9,8 @@
 				$issue = $res->fetch_assoc();
 				$issue['user'] = userObj($issue['user']);
 				$issue['comments'] = messages($issue['id'],'issue');
+				$issue['statuses'] = possibleStatuses();
+				$issue['priorities'] = possiblePriorities();
 				return $issue;
 			}
 		}
@@ -42,4 +44,42 @@
 		}
 		return false;
 	}
+	function possibleStatuses(){
+		$ret = array();
+		if($res = query("SELECT id,name FROM `statuses` ORDER BY id")){
+			while($status = $res->fetch_assoc()){
+				array_push($ret,$status);
+			}
+		}
+		return $ret;
+	}
+	function possiblePriorities(){
+		$ret = array();
+		if($res = query("SELECT id,name,color FROM `priorities` ORDER BY id")){
+			while($priority = $res->fetch_assoc()){
+				array_push($ret,$priority);
+			}
+		}
+		return $ret;
+	}
+	function setStatus($id,$sid){
+		return query("UPDATE `issues` SET st_id = %d WHERE id = %d",array($sid,$id)) !== false;
+	}
+	function setPriority($id,$pid){
+		return query("UPDATE `issues` SET pr_id = %d WHERE id = %d",array($pid,$id)) !== false;
+	}
+	function statusName($id){
+		if($res = query("SELECT name FROM `statuses` WHERE id = %d",array($id))){
+			$res = $res->fetch_assoc();
+			return $res['name'];
+		}
+		return '(none)';
+	}
+	function priorityName($id){
+		if($res = query("SELECT name FROM `proiorities` WHERE id = %d",array($id))){
+			$res = $res->fetch_assoc();
+			return $res['name'];
+		}
+		return '(none)';
+	}
 ?>