Explorar o código

Add busy indicators

Johannes Zellner %!s(int64=11) %!d(string=hai) anos
pai
achega
b33c85d005
Modificáronse 3 ficheiros con 56 adicións e 7 borrados
  1. 24 0
      public/index.css
  2. 21 7
      public/index.html
  3. 11 0
      public/index.js

+ 24 - 0
public/index.css

@@ -35,3 +35,27 @@
     top: 20px;
     right: 20px;
 }
+
+.spinner {
+    background-color: transparent;
+    border: 3px dashed #03a9f4;
+    border-radius: 50%;
+    border-top-color: transparent;
+    border-right-color: transparent;
+    width: 1em;
+    height: 1em;
+    display: inline-block;
+    vertical-align: middle;
+    box-sizing: border-box;
+    animation: spinner-animation 0.65s infinite linear;
+    font-size: 35px;
+}
+
+@keyframes spinner-animation {
+    0% {
+        transform:rotate(0deg)
+    }
+    100% {
+        transform:rotate(360deg)
+    }
+}

+ 21 - 7
public/index.html

@@ -113,6 +113,7 @@
   <button class="btn btn-default btn-fab" data-toggle="modal" data-target="#modalSettings"><i class="mdi mdi-dots-horizontal"></i></button>
 </div>
 
+
 <div class="container main">
   <div class="row">
     <div class="col-md-2 col-md-offset-5">
@@ -129,16 +130,29 @@
   </div>
   <div class="row">
     <div class="col-md-2">
-      <button class="btn btn-primary btn-sm" ng-repeat="tag in tags" ng-click="addFilterTag(tag)">{{tag.name}}</button>
+      <div ng-hide="tagsBusy">
+        <button class="btn btn-primary btn-sm" ng-repeat="tag in tags" ng-click="addFilterTag(tag)">{{tag.name}}</button>
+      </div>
+      <div ng-show="tagsBusy">
+        <center><i class="spinner"></i></center>
+      </div>
     </div>
     <div class="col-md-8">
-      <div class="well well-sm thing" ng-repeat="thing in things">
-          <div class="col-md-12 thing-title-date">
-            {{thing.createdAt | prettyDateOffset}}
-            <button class="btn btn-xs btn-default" ng-click="showDelThing(thing._id)">delete</button>
-            <button class="btn btn-xs btn-default" ng-click="showEditThing(thing._id, thing.content)">edit</button>
+      <div ng-hide="thingsBusy">
+        <div class="well well-sm thing" ng-repeat="thing in things">
+            <div class="col-md-12 thing-title-date">
+              {{thing.createdAt | prettyDateOffset}}
+              <button class="btn btn-xs btn-default" ng-click="showDelThing(thing._id)">delete</button>
+              <button class="btn btn-xs btn-default" ng-click="showEditThing(thing._id, thing.content)">edit</button>
+          </div>
+          <div class="content" marked="thing.richContent"></div>
         </div>
-        <div class="content" marked="thing.richContent"></div>
+      </div>
+      <div ng-show="thingsBusy">
+        <br/>
+        <br/>
+        <br/>
+        <center><i class="spinner"></i></center>
       </div>
     </div>
   </div>

+ 11 - 0
public/index.js

@@ -17,6 +17,9 @@ app.controller('MainController', function ($scope, $http, $timeout, $document) {
     $scope.things = [];
     $scope.tags = [];
     $scope.filter = '';
+    $scope.thingsBusy = true;
+    $scope.tagsBusy = true;
+
     $scope.addFormData = {
         busy: true,
         content: ''
@@ -117,6 +120,8 @@ app.controller('MainController', function ($scope, $http, $timeout, $document) {
     };
 
     $scope.fetchThings = function () {
+        $scope.thingsBusy = true;
+
         var url = '/api/things';
 
         if ($scope.filter) {
@@ -125,16 +130,22 @@ app.controller('MainController', function ($scope, $http, $timeout, $document) {
 
         $http.get(url, {}).then(function (result) {
             angular.copy(result.data.things, $scope.things);
+            $scope.thingsBusy = false;
         }, function (result) {
             console.error('error:', result);
+            $scope.thingsBusy = false;
         });
     };
 
     $scope.fetchTags = function () {
+        $scope.tagsBusy = true;
+
         $http.get('/api/tags', {}).then(function (result) {
             angular.copy(result.data.tags, $scope.tags);
+            $scope.tagsBusy = false;
         }, function (result) {
             console.error('error:', result);
+            $scope.tagsBusy = false;
         });
     };