Browse Source

Performance fixes

Nathaniel van Diepen 8 years ago
parent
commit
2627cac074
5 changed files with 64 additions and 53 deletions
  1. 0 0
      performance-profile.json
  2. 9 6
      site/api/index.php
  3. 8 6
      site/index.css
  4. 9 10
      site/index.php
  5. 38 31
      site/js/index.js

File diff suppressed because it is too large
+ 0 - 0
performance-profile.json


+ 9 - 6
site/api/index.php

@@ -108,6 +108,7 @@
 			if($res[0]){
 				$res = explode('
',$res[1]);
 				$channels = array();
+				$flags = array();
 				foreach($res as $k => $row){
 					if($k != count($res)-1){
 						$flags_list = str_split(preg_replace('/^Access flag\(s\) \+(.+) in .+$/i','\1',$row));
@@ -135,11 +136,13 @@
 									);
 									$flags_list = str_split(preg_replace('/^\d+\s+.+\s+\+(.+)\s+\[.+/i','\1',$row2));
 									foreach($flags_list as $kk => $flag){
-										$name = channel_flag_name($flag);
-										array_push($user['flags'],array(
-											'flag'=>$flag,
-											'name'=>$name
-										));
+										if($flag!=' '){
+											array_push($user['flags'],$flag);
+											$name = channel_flag_name($flag);
+											if(!isset($flags[$flag])){
+												$flags[$flag] = $name;
+											}
+										}
 									}
 									array_push($users,$user);
 								}
@@ -149,7 +152,7 @@
 						array_push($channels,$chan);
 					}
 				}
-				die('{"code":0,"channels":'.json_encode($channels).'}');
+				die('{"code":0,"channels":'.json_encode($channels).',"flags": '.json_encode($flags).'}');
 			}else{
 				die('{"code":1,"message":"'.__('Cannot fetch channels').'"}');
 			}

+ 8 - 6
site/index.css

@@ -14,17 +14,19 @@ html,body{
 	background-size: auto auto;
 	color: white;
 }
-#loading{
-	display: none;
-	position: absolute;
+#user-menu{
+	z-index: 100;
+}
+.loading{
+	position: fixed;
 	left: 0px;
-	top: 0px;
+	top: 60px;
 	width: 100%;
 	height: 100%;
-	z-index: 100;
+	z-index: 50;
 	background-color: rgba(0, 0, 0, 0.5);
 }
-#loading>div{
+.loading>div.loading-spinner{
 	background-image: url(img/loading.gif);
 	left: 50%;
 	top: 50%;

+ 9 - 10
site/index.php

@@ -35,7 +35,7 @@
 			<script src="//cdnjs.cloudflare.com/ajax/libs/authy-forms.js/2.0/form.authy.min.js"></script>
 		<?php } ?>
 		<script src="//cdnjs.cloudflare.com/ajax/libs/jquery-url-parser/2.3.1/purl.min.js"></script>
-		<script src="//cdnjs.cloudflare.com/ajax/libs/handlebars.js/3.0.0/handlebars.min.js"></script>
+		<script src="//cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.2/handlebars.min.js"></script>
 		<?php if(get_conf('persona-endpoint') != 'none'){ ?>
 			<script src="//login.persona.org/include.js"></script>
 		<?php } ?>
@@ -181,12 +181,14 @@
 											</td>
 										</tr>
 										{{#each this.flags}}
-											<tr class='treegrid-{{this.flag}} treegrid-parent-{{../id}}'>
-												<td></td>
-												<td>
-													{{this.name}}
-												</td>
-											</tr>
+											{{#if this.flag}}
+												<tr class='treegrid-{{this.flag}} treegrid-parent-{{../id}}'>
+													<td></td>
+													<td>
+														{{this.name}}
+													</td>
+												</tr>
+											{{/if}}
 										{{/each}}
 									{{/each}}
 									</table>
@@ -577,8 +579,5 @@
 					}
 				?>
 			</div>
-			<div id="loading">
-				<div class="ui-widget ui-state-default ui-corner-all"></div>
-			</div>
 	</body>
 </html>

+ 38 - 31
site/js/index.js

@@ -3,11 +3,6 @@ $(function(){
 	if(location.host != purl(__HOSTNAME__).attr('host')){
 		location.href = __HOSTNAME__;
 	}
-	$(document).ajaxStart(function(){
-		$("#loading").show();
-	}).ajaxStop(function(){
-		$("#loading").hide();
-	});
 	Pomo.domain = 'messages';
 	Pomo.unescapeStrings = true;
 	var _ = window._ = function(text){
@@ -18,6 +13,7 @@ $(function(){
 				return text;
 			}
 		},
+		loadingHTML = '<div class="loading"><div class="ui-widget ui-state-default ui-corner-all loading-spinner"></div></div>',
 		dialogs = $('#dialogs').children('div'),
 		memos,
 		news,
@@ -432,6 +428,7 @@ $(function(){
 		};
 		window.FetchMemos = function(once){
 			console.log(_("Fetching Memos"));
+			$('#memos').prepend(loadingHTML);
 			$.ajax(__HOSTNAME__+'site/api/?action=get-memos',{
 				success: function(d){
 					if(d.log){
@@ -482,6 +479,7 @@ $(function(){
 		};
 		window.DeleteMemo = function(id,callback){
 			console.log(_("Deleting memo")+": "+id);
+			$('#memos').prepend(loadingHTML);
 			$.ajax(__HOSTNAME__+'site/api/?action=delete-memo&id='+id,{
 				success: function(d){
 					if(d.log){
@@ -497,6 +495,7 @@ $(function(){
 					if(typeof callback != 'undefined'){
 						callback();
 					}
+					$('#memos>.loading').remove();
 				},
 				error: function(xhr,msg,e){
 					console.error(e);
@@ -508,6 +507,7 @@ $(function(){
 		};
 		window.FetchNews = function(once){
 			console.log(_("Fetching News"));
+			$('#news').prepend(loadingHTML);
 			$.ajax(__HOSTNAME__+'site/api/?action=get-news',{
 				success: function(d){
 					if(d.log){
@@ -550,6 +550,7 @@ $(function(){
 		};
 		window.FetchChannels = function(){
 			console.log(_("Fetching Channels"));
+			$('#channels').prepend(loadingHTML);
 			$.ajax(__HOSTNAME__+'site/api/?action=get-channels',{
 				success: function(d){
 					if(d.log){
@@ -562,18 +563,20 @@ $(function(){
 						location.reload();
 					}
 					var i,
-						n;
+						n,
+						div = $('<div>');
 					if(d.channels){
 						for(i in d.channels){
 							n = d.channels[i];
 							d.channels[i] = n;
 						}
 					}
-					$('#channels').html(templates.channels(d)).find('button').button();
-					translate('#channels');
-					$('#channels').find('.tree').treegrid({
+					div.append(templates.channels(d)).find('button').button();
+					translate(div);
+					div.find('.tree').treegrid({
 						initialState: 'collapsed'
 					});
+					$('#channels').html(div.children());
 					$('body').resize();
 				},
 				error: function(xhr,msg,e){
@@ -587,6 +590,7 @@ $(function(){
 		window.DeleteChannel = function(channel){
 			if(confirm(_('Are you sure you want to delete channel')+' '+channel)){
 				console.log(_("Deleting channel")+": "+channel);
+				$('#channels').prepend(loadingHTML);
 				$.ajax(__HOSTNAME__+'site/api/?action=delete-channel',{
 					data: {
 						channel: channel
@@ -605,6 +609,7 @@ $(function(){
 						if(typeof callback != 'undefined'){
 							callback();
 						}
+						$('#channels>.loading').remove();
 					},
 					error: function(xhr,msg,e){
 						console.error(e);
@@ -617,29 +622,31 @@ $(function(){
 		};
 		window.RegisterChannel = function(channel){
 			console.log(_("Registering channel")+": "+channel);
-				$.ajax(__HOSTNAME__+'site/api/?action=register-channel',{
-					data: {
-						channel: channel
-					},
-					success: function(d){
-						if(d.log){
-							console.log(d.log);
-						}
-						if(d.message){
-							alert(d.message);
-						}
-						if(d.code!==0){
-							location.reload();
-						}
-						window.FetchChannels(true);
-					},
-					error: function(xhr,msg,e){
-						console.error(e);
-						alert(_("Could not ping server")+": "+msg);
+			$('#channels').prepend(loadingHTML);
+			$.ajax(__HOSTNAME__+'site/api/?action=register-channel',{
+				data: {
+					channel: channel
+				},
+				success: function(d){
+					if(d.log){
+						console.log(d.log);
+					}
+					if(d.message){
+						alert(d.message);
+					}
+					if(d.code!==0){
 						location.reload();
-					},
-					dataType: 'json'
-				});
+					}
+					window.FetchChannels(true);
+					$('#channels>.loading').remove();
+				},
+				error: function(xhr,msg,e){
+					console.error(e);
+					alert(_("Could not ping server")+": "+msg);
+					location.reload();
+				},
+				dataType: 'json'
+			});
 		};
 		window.ModifyChannelAccess = function(channel,user,id){
 			var d = $('#channel-flags-diag');

Some files were not shown because too many files changed in this diff