Alan Lam пре 8 година
родитељ
комит
4970bc8b28
4 измењених фајлова са 159 додато и 77 уклоњено
  1. 41 21
      controllers/account.php
  2. 21 0
      engine/account_icon.php
  3. 13 1
      public/js/app.js
  4. 84 55
      views/account.php

+ 41 - 21
controllers/account.php

@@ -8,12 +8,13 @@ $users_pending_verification = 0;
 $tests_pending_verification = 0;
 $tests_remaining = 0;
 
-$links = [];
+$icons = [];
 
 if(Core::$user->level >= User::LEVEL_ADMIN) {
-	$links["/account/customers"] = "Customers";
-	$links["/account/map-overview"] = "Map Overview";
-	$links["/account/users"] = (Core::$user->level == User::LEVEL_SUPERADMIN ? "Users" : "Testers");
+
+	$icons[] = new AccountIcon("Customers", "/account/customers", "warehouse");
+	$icons[] = new AccountIcon("Map Overview", "/account/map-overview", "map-marked");
+	$icons[] = new AccountIcon((Core::$user->level == User::LEVEL_SUPERADMIN ? "Users" : "Testers"), "/account/users", "users");
 
 	$users = User::query(["level" => User::LEVEL_UNVERIFIED]);
 	$tests = Test::query(["status" => Test::STATUS_PENDING_VERIFICATION]);
@@ -23,52 +24,71 @@ if(Core::$user->level >= User::LEVEL_ADMIN) {
 }
 
 if(Core::$user->level >= User::LEVEL_CUSTOMER) {
-	$links["/account/reports"] = "Reports";
-	$links["/account/projects"] = "Projects";
-	$links["/account/locations"] = "Locations";
-	$links["/account/templates"] = "Templates";
+	$icons[] = new AccountIcon("Reports", "/account/reports", "chart-pie");
+	$icons[] = new AccountIcon("Projects", "/account/projects", "list");
+	$icons[] = new AccountIcon("Locations", "/account/locations", "map-marker");
+	$icons[] = new AccountIcon("Templates", "/account/templates", "file-alt");
 }
 
 if(Core::$user->level >= User::LEVEL_TESTER) {
-	$links["/account/tests"] = "Tests";
-	$links["/account/practice"] = "Practice";
-
 	$tests = Core::$user->getPendingTests();
 	$tests_remaining = count($tests);
 
+	$tests_icon = new AccountIcon("Tests", "/account/tests", "clipboard-check");
+	$tests_icon->setCounter($tests_remaining);
+
+	$icons[] = $tests_icon;
+	$icons[] = new AccountIcon("Practice", "/account/practice", "chalkboard-teacher");
 }
 
 if(Core::$user->level == User::LEVEL_TESTER) {
-	$links["/account/addresses"] = "Addresses";
-	$links["/account/tests/completed"] = "Tests (Completed)";
+	$icons[] = new AccountIcon("Addresses", "/account/addresses", "address-book");
+	$icons[] = new AccountIcon("Tests (Completed)", "/account/tests/completed", "check");
 }
 
 if(Core::$user->level == User::LEVEL_REGISTERED) {
-	$links["/account/submit-id"] = "Submit ID";
+	$icons[] = new AccountIcon("Submit ID", "/account/submit-id", "id-card");
 }
 
 if(!Core::$user->terms_accepted) {
-	$links = [];
+	$icons = [];
 }
 
-$links["/account/settings"] = "Settings";
+$icons[] = new AccountIcon("Settings", "/account/settings", "cog");
 
-asort($links);
+usort($icons, function($a, $b) {
+	return $a->name <=> $b->name;
+});
 
 // Actions
 $actions = [];
 if(Core::$user->level == User::LEVEL_DEACTIVATED) {
-	$actions["/account/reactivate"] = "Reactivate Account";
+	$actions[] = new AccountIcon("Reactivate Account", "/account/reactivate", "user-check");
 }
 else if(Core::$user->level == User::LEVEL_TESTER) {
-	$actions["/account/deactivate"] = "Deactivate Account...";
+	$actions[] = new AccountIcon("Deactivate Account...", "/account/deactivate", "user-times");
+}
+
+$actions[] = new AccountIcon("Delete Account...", "/account/delete", "user-slash");
+
+// To-do
+$to_do = [];
+if($users_pending_verification) {
+	$icon = new AccountIcon("Verify Users", "/account/users?level=" . User::LEVEL_UNVERIFIED, "user-check");
+	$icon->setCounter($users_pending_verification);
+	$to_do[] = $icon;
+}
+
+if($tests_pending_verification) {
+	$icon = new AccountIcon("Verify Tests", "/account/tests?status=" . Test::STATUS_PENDING_VERIFICATION, "clipboard-check");
+	$icon->setCounter($tests_pending_verification);
+	$to_do[] = $icon;
 }
-$actions["/account/delete"] = "Delete Account...";
 
 $referrals = Core::$user->getReferrals();
 
 View::includeOnce("header", compact("page_title"));
-View::include("account", compact("links", "actions", "referrals", "users_pending_verification", "tests_pending_verification", "tests_remaining"));
+View::include("account", compact("icons", "actions", "to_do", "referrals"));
 View::includeOnce("footer");
 
 ?>

+ 21 - 0
engine/account_icon.php

@@ -0,0 +1,21 @@
+<?php
+
+class AccountIcon {
+
+	public $name = "";
+	public $icon = "";
+	public $url = "";
+
+	public $counter = false;
+
+	public function __construct($name, $url, $icon) {
+		$this->name = $name;
+		$this->icon = $icon;
+		$this->url = $url;
+	}
+
+	public function setCounter($counter) {
+		$this->counter = $counter;
+	}
+
+}

+ 13 - 1
public/js/app.js

@@ -43,7 +43,19 @@ $(function() {
 		specialSpan.attr("class", specialClass);
 	});
 
-    var clipboard = new ClipboardJS(".btn[data-clipboard-target]");
+    var clipboard = new ClipboardJS("[data-clipboard-target], [data-clipboard-text]");
+	clipboard.on("success", function(e) {
+
+		$(e.trigger).tooltip("hide").attr("data-original-title", "Copied!").tooltip("show");
+
+		e.clearSelection();
+	});
+
+	let hasTooltips = $('[data-toggle="tooltip"]').length > 0;
+	if(hasTooltips) {
+		initialiseTooltips();
+	}
+
 
 });
 

+ 84 - 55
views/account.php

@@ -29,76 +29,106 @@
 	?>
 
 	<div class="row">
-		<div class="col-lg-4 mb-3 mb-lg-0">
+		<div class="col-xl mb-3 mb-lg-0">
 			<h3>Main Menu</h3>
-			<div class="list-group mb-3">
+			<div class="row">
 			<?php
-			foreach($links as $path => $text) {
+			foreach($icons as $icon) {
 				?>
-				<a class="list-group-item list-group-item-action" href="<?=htmlspecialchars($path)?>">
-					<?=htmlspecialchars($text)?>
-				</a>
+				<div class="col-6 col-sm-4 text-center">
+					<a class="btn btn-light btn-block mb-3 p-2" href="<?=htmlspecialchars($icon->url)?>">
+						<?php
+						if($icon->counter) {
+							?>
+							<span class="fa-layers fa-fw fa-3x mb-2">
+								<i class="fal fa-<?=htmlspecialchars($icon->icon)?>"></i>
+								<span class="fa-layers-counter fa-layers-bottom-right"><?=number_format($icon->counter)?></span>
+							</span>
+							<?php
+						}
+						else {
+							?>
+							<i class="fal fa-3x fa-<?=htmlspecialchars($icon->icon)?> mb-2"></i>
+							<?php
+						}
+						?>
+						<br />
+						<?=htmlspecialchars($icon->name)?>
+					</a>
+				</div>
 				<?php
 			}
 			?>
 			</div>
 			<h3>Actions</h3>
-			<div class="list-group mb-3">
+			<div class="row">
 			<?php
-			foreach($actions as $path => $text) {
-				$text_class = preg_match("/delete/i", $text) ? "text-danger" : "";
+			foreach($actions as $icon) {
+				$button_class = preg_match("/delete/i", $icon->name) ? "btn-danger" : "btn-light";
 				?>
-				<a class="list-group-item list-group-item-action <?=$text_class?>" href="<?=htmlspecialchars($path)?>">
-					<?=htmlspecialchars($text)?>
-				</a>
+				<div class="col-6 col-sm-4 text-center">
+					<a class="btn <?=$button_class?> btn-block mb-3 p-2" href="<?=htmlspecialchars($icon->url)?>">
+						<?php
+						if($icon->counter) {
+							?>
+							<span class="fa-layers fa-fw fa-3x mb-2">
+								<i class="fal fa-<?=htmlspecialchars($icon->icon)?>"></i>
+								<span class="fa-layers-counter fa-layers-bottom-right"><?=number_format($icon->counter)?></span>
+							</span>
+							<?php
+						}
+						else {
+							?>
+							<i class="fal fa-3x fa-<?=htmlspecialchars($icon->icon)?> mb-2"></i>
+							<?php
+						}
+						?>
+						<br />
+						<?=htmlspecialchars($icon->name)?>
+					</a>
+				</div>
 				<?php
 			}
 			?>
 			</div>
 		</div>
-		<div class="col-lg mb-3 mb-lg-0">
+		<div class="col-xl mb-3 mb-lg-0">
 
 			<?php
-			$has_to_do = !empty($users_pending_verification) || !empty($tests_pending_verification) || !empty($tests_remaining);
-
-			if($has_to_do) {
+			if($to_do) {
 				?>
 				<h3>To-Do</h3>
 
+				<div class="row">
 				<?php
-				if($users_pending_verification) {
-					$s = ($users_pending_verification == 1) ? "" : "s";
-					?>
-					<div class="alert alert-info mb-3 d-flex flex-row justify-content-between">
-						<div class="align-self-center">
-							<i class="fal fa-fw fa-info-circle"></i> <?=number_format($users_pending_verification)?> user<?=$s?> to be verified.
-						</div>
-						<a class="btn btn-primary" href="/account/users?level=<?=User::LEVEL_UNVERIFIED?>">View</a>
-					</div>
-					<?php
-				}
-				if($tests_pending_verification) {
-					$s = ($tests_pending_verification == 1) ? "" : "s";
+				foreach($to_do as $icon) {
 					?>
-					<div class="alert alert-info mb-3 d-flex flex-row justify-content-between">
-						<div class="align-self-center">
-							<i class="fal fa-fw fa-info-circle"></i> <?=number_format($tests_pending_verification)?> test<?=$s?> to be verified.
-						</div>
-						<a class="btn btn-primary" href="/account/tests?status=<?=Test::STATUS_PENDING_VERIFICATION?>">View</a>
-					</div>
-					<?php
-				}
-				if($tests_remaining) {
-					$s = ($tests_remaining == 1) ? "" : "s";
-					?>
-					<div class="alert alert-info mb-3 d-flex flex-row justify-content-between">
-						<div class="align-self-center">
-							<i class="fal fa-fw fa-info-circle"></i> <?=number_format($tests_remaining)?> test<?=$s?> remaining.
-						</div>
-						<a class="btn btn-primary" href="/account/tests">View</a>
+					<div class="col-6 col-sm-4 text-center">
+						<a class="btn btn-primary btn-block mb-3 p-2" href="<?=htmlspecialchars($icon->url)?>">
+							<?php
+							if($icon->counter) {
+								?>
+								<span class="fa-layers fa-fw fa-3x mb-2">
+									<i class="fal fa-<?=htmlspecialchars($icon->icon)?>"></i>
+									<span class="fa-layers-counter fa-layers-bottom-right"><?=number_format($icon->counter)?></span>
+								</span>
+								<?php
+							}
+							else {
+								?>
+								<i class="fal fa-3x fa-<?=htmlspecialchars($icon->icon)?> mb-2"></i>
+								<?php
+							}
+							?>
+							<br />
+							<?=htmlspecialchars($icon->name)?>
+						</a>
 					</div>
 					<?php
 				}
+				?>
+				</div>
+				<?php
 			}
 
 			if(Core::$user->level != User::LEVEL_DEACTIVATED && !Core::$user->terms_accepted) {
@@ -159,20 +189,19 @@
 					</span>
 					<span><?=number_format(count($referrals))?></span>
 				</div>
-				<div class="list-group-item d-flex align-items-center justify-content-between">
+				<div class="list-group-item d-flex justify-content-between">
 					<span>
 						<i class="fal fa-fw fa-external-link"></i>
 						Referral Link:
 					</span>
-					<div class="input-group input-group-sm w-50">
-						<input class="form-control w-auto" type="text" id="referral-link" readonly value="<?=PROTOCOL?>://<?=DOMAIN?>/register?r=<?=Core::$user->id?>" />
-						<div class="input-group-append">
-							<button class="btn btn-secondary" data-clipboard-target="#referral-link" data-toggle="tooltip" title="Copy to clipboard">
-								<i class="fal fa-fw fa-clipboard"></i>
-								<span class="sr-only">Copy to clipboard</span>
-							</button>
-						</div>
-					</div>
+
+					<span>
+						<a href="#" data-clipboard-text="<?=PROTOCOL?>://<?=DOMAIN?>/register?r=<?=Core::$user->id?>" data-toggle="tooltip" data-title="Copy to clipboard">
+							<i class="fal fa-fw fa-clipboard"></i>
+							Copy to clipboard
+						</a>
+					</span>
+
 				</div>
 			</div>
 		</div>