瀏覽代碼

Added alerts.

KrisVos130 9 年之前
父節點
當前提交
4818859e47

+ 17 - 4
app/client/app.css

@@ -169,6 +169,9 @@
 
 html, body {
     height: 100%;
+    background: #50a3a2;
+    background: -webkit-linear-gradient(top left, #50a3a2 0%, #53e3a6 100%);
+    background: linear-gradient(to bottom right, #50a3a2 0%, #53e3a6 100%);
 }
 
 body {
@@ -307,7 +310,7 @@ form {
     z-index: 2;
 }
 
-form input, .croom {
+form input, .croom, .calert {
     -webkit-appearance: none;
     -moz-appearance: none;
     appearance: none;
@@ -845,21 +848,25 @@ footer .fa {
     margin-top: 10%;
 }
 
-#croom_container {
+#croom_container, #calert_container {
     margin-left: auto;
     margin-right: auto;
     margin-bottom: 10px;
     width: 304px !important;
 }
 
-.croom_label {
+.croom_label, .calert_label {
     color: white;
 }
 
-.croom {
+.croom, .calert {
     width: 304px !important;
 }
 
+#calert-priority > option {
+    color: black;
+}
+
 #spinner {
     font-size: 200px;
     color: bisque;
@@ -1252,4 +1259,10 @@ nav form input[type="image"]{
 ::-webkit-scrollbar-thumb {
     border-radius: 10px;
     background-color: white;
+}
+
+::-webkit-scrollbar-track-piece {
+    background: #50a3a2;
+    background: -webkit-linear-gradient(top left, #50a3a2 0%, #53e3a6 100%);
+    background: linear-gradient(to bottom right, #50a3a2 0%, #53e3a6 100%);
 }

+ 39 - 1
app/client/client.js

@@ -7,6 +7,7 @@ Meteor.startup(function() {
 Meteor.subscribe("queues");
 Meteor.subscribe("chat");
 Meteor.subscribe("playlists");
+Meteor.subscribe("alerts");
 
 var minterval;
 var hpSound = undefined;
@@ -79,7 +80,6 @@ Handlebars.registerHelper('active', function(path) {
     return curPath() == path ? 'active' : '';
 });
 
-
 Template.header.helpers({
     currentUser: function() {
         return Meteor.user();
@@ -536,6 +536,12 @@ Template.room.onRendered(function() {
     });
 });
 
+Template.alerts.helpers({
+    alerts: function() {
+        return Alerts.find({active: true});
+    }
+});
+
 Template.room.helpers({
     chat: function() {
         Meteor.setTimeout(function() {
@@ -666,6 +672,38 @@ Template.room.helpers({
     }
 });
 
+var allAlertSub = undefined;
+
+Template.alertsDashboard.onCreated(function() {
+    if (allAlertSub === undefined) {
+        allAlertSub = Meteor.subscribe("allAlerts");
+    }
+});
+
+Template.alertsDashboard.helpers({
+    "activeAlerts": function() {
+        return Alerts.find({active: true});
+    },
+    "inactiveAlerts": function() {
+        return Alerts.find({active: false});
+    }
+});
+
+Template.alertsDashboard.events({
+    "click #calart-create": function() {
+        Meteor.call("addAlert", $("#calert-description").val(), $("#calert-priority").val().toLowerCase(), function (err, res) {
+            if (err) {
+                alert("Error " + err.error + ": " + err.reason);
+            } else {
+                $("#calert-description").val("");
+            }
+        });
+    },
+    "click #ralert-button": function() {
+        Meteor.call("removeAlerts");
+    }
+});
+
 Template.admin.helpers({
   queueCount: function(i) {
       var queues = Queues.find({}).fetch();

+ 9 - 0
app/client/head.html

@@ -55,4 +55,13 @@
         ga('send', 'pageview');
 
     </script>
+    <script type="text/javascript">
+        window.doorbellOptions = {
+            appKey: 'v2Gu14c8s9HgBsAFCXNWIm2vlk11N12Plt2Wu5k2MbQIkM1Ao6kOTCbfN95ElEVM',
+            hideEmail: true
+        };
+        (function(d, t) {
+            var g = d.createElement(t);g.id = 'doorbellScript';g.type = 'text/javascript';g.async = true;g.src = 'https://embed.doorbell.io/button/2408?t='+(new Date().getTime());(d.getElementsByTagName('head')[0]||d.getElementsByTagName('body')[0]).appendChild(g);
+        }(document, 'script'));
+    </script>
 </head>

+ 23 - 10
app/client/routes.js

@@ -47,18 +47,31 @@ Router.route("/admin", {
 });
 
 Router.route("/stations", {
-  action: function() {
-    var user = Meteor.users.findOne({});
-    if (user !== undefined && user.profile !== undefined && user.profile.rank === "admin") {
-        this.render("stations");
-    } else {
-        this.redirect("/");
+    waitOn: function() {
+        return Meteor.subscribe("isAdmin", Meteor.userId());
+    },
+    action: function() {
+      var user = Meteor.users.findOne({});
+      if (user !== undefined && user.profile !== undefined && user.profile.rank === "admin") {
+          this.render("stations");
+      } else {
+          this.redirect("/");
+      }
     }
-  }
-})
+});
 
-Router.route("/vis", {
-    template: "visualizer"
+Router.route("/admin/alerts", {
+    waitOn: function() {
+        return Meteor.subscribe("isAdmin", Meteor.userId());
+    },
+    action: function() {
+        var user = Meteor.users.findOne({});
+        if (user !== undefined && user.profile !== undefined && user.profile.rank === "admin") {
+            this.render("alertsDashboard");
+        } else {
+            this.redirect("/");
+        }
+    }
 });
 
 Router.route("/:type", {

+ 1 - 0
app/client/templates/about.html

@@ -1,4 +1,5 @@
 <template name="about">
+    {{> alerts}}
     <div class="landing">
 	    {{> header}}
         <div class="row">

+ 1 - 0
app/client/templates/admin.html

@@ -1,4 +1,5 @@
 <template name="admin">
+    {{> alerts}}
     <div class="landing">
         {{> header}}
           <div class="row" style="margin-top: 20px;">

+ 7 - 0
app/client/templates/alerts.html

@@ -0,0 +1,7 @@
+<template name="alerts">
+    {{#each alerts}}
+        <div class="alert alert-{{priority}}" style="margin: 0" role="alert">
+            <a href="#" class="alert-link">{{description}}</a>
+        </div>
+    {{/each}}
+</template>

+ 27 - 0
app/client/templates/alertsDashboard.html

@@ -0,0 +1,27 @@
+<template name="alertsDashboard">
+    {{> alerts}}
+    <div class="landing">
+        {{> header}}
+        <div class="row">
+            <div class="col-md-4 col-md-offset-4">
+                <button class="btn btn-block btn-danger" id="ralert-button">Remove all alerts.</button>
+                <div id="calert_container">
+                    <label for="calert-description" class="calert_label">Alert Description:</label>
+                    <div class="input-group">
+                        <input type="text" class="calert" id="calert-description" name="calert" required />
+                    </div>
+                    <label for="calert-priority" class="croom_label">Alert Priority:</label>
+                    <div class="input-group">
+                        <select class="calert" id="calert-priority" name="calert" required>
+                            <option selected>Danger</option>
+                            <option>Warning</option>
+                            <option>Primary</option>
+                            <option>Success</option>
+                        </select>
+                    </div>
+                    <button class="btn btn-warning btn-block" id="calart-create">Create</button>
+                </div>
+            </div>
+        </div>
+    </div>
+</template>

+ 1 - 0
app/client/templates/api.html

@@ -1,4 +1,5 @@
 <template name="api">
+    {{> alerts}}
     <div class="landing">
 	    {{> header}}
         <div class="row">

+ 0 - 10
app/client/templates/dashboard.html

@@ -13,14 +13,4 @@
           </div>
        {{/each}}
     </div>
-    
-    <script type="text/javascript">
-        window.doorbellOptions = {
-            appKey: 'v2Gu14c8s9HgBsAFCXNWIm2vlk11N12Plt2Wu5k2MbQIkM1Ao6kOTCbfN95ElEVM',
-            hideEmail: true
-        };
-        (function(d, t) {
-            var g = d.createElement(t);g.id = 'doorbellScript';g.type = 'text/javascript';g.async = true;g.src = 'https://embed.doorbell.io/button/2408?t='+(new Date().getTime());(d.getElementsByTagName('head')[0]||d.getElementsByTagName('body')[0]).appendChild(g);
-        }(document, 'script'));
-    </script>
 </template>

+ 1 - 0
app/client/templates/home.html

@@ -1,4 +1,5 @@
 <template name="home">
+    {{> alerts}}
     <div class="homepage">
         <!--<div class="alert alert-success alert-dismissible" role="alert" style="margin-bottom: 0">-->
             <!--<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true"><i class="fa fa-times"></i></span></button>-->

+ 1 - 0
app/client/templates/login.html

@@ -1,4 +1,5 @@
 <template name="login">
+    {{> alerts}}
   <div class="landing">
     {{> header}}
     <div class="container">

+ 1 - 0
app/client/templates/privacy.html

@@ -1,4 +1,5 @@
 <template name="privacy">
+    {{> alerts}}
   <div class="landing">
     {{> header}}
     <div class="row">

+ 1 - 0
app/client/templates/profile.html

@@ -1,4 +1,5 @@
 <template name="profile">
+    {{> alerts}}
     <div class="landing">
       {{> header}}
       <div class="row">

+ 1 - 0
app/client/templates/register.html

@@ -1,4 +1,5 @@
 <template name="register">
+    {{> alerts}}
   <div class="landing">
     {{> header}}
     <div class="container">

+ 1 - 0
app/client/templates/room.html

@@ -1,4 +1,5 @@
 <template name="room">
+    {{> alerts}}
     {{#if loaded}}
         <div class="landing">
             <div class="row">

+ 1 - 0
app/client/templates/stations.html

@@ -1,4 +1,5 @@
 <template name="stations">
+    {{> alerts}}
   <div class="landing">
     {{> header}}
     <div class="row">

+ 1 - 0
app/client/templates/terms.html

@@ -1,4 +1,5 @@
 <template name="terms">
+    {{> alerts}}
   <div class="landing">
     {{> header}}
     <div class="row">

+ 2 - 1
app/collections/collections.js

@@ -2,4 +2,5 @@ Playlists = new Mongo.Collection("playlists");
 Rooms = new Mongo.Collection("rooms");
 Queues = new Mongo.Collection("queues");
 Reports = new Mongo.Collection("reports");
-Chat = new Mongo.Collection("chat");
+Chat = new Mongo.Collection("chat");
+Alerts = new Mongo.Collection("alerts");

+ 33 - 0
app/server/server.js

@@ -10,6 +10,8 @@ Meteor.startup(function() {
     }
 });
 
+Alerts.update({active: true}, {$set: {active: false}}, { multi: true });
+
 var stations = [];
 
 var chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_";
@@ -391,6 +393,14 @@ ServiceConfiguration.configurations.insert({
     secret: "375939d001ef1a0ca67c11dbf8fb9aeaa551e01b"
 });
 
+Meteor.publish("alerts", function() {
+    return Alerts.find({active: true})
+});
+
+Meteor.publish("allAlerts", function() {
+    return Alerts.find({active: false})
+});
+
 Meteor.publish("playlists", function() {
     return Playlists.find({})
 });
@@ -425,6 +435,29 @@ function isAdmin() {
 }
 
 Meteor.methods({
+    removeAlerts: function() {
+        if (isAdmin()) {
+            Alerts.update({active: true}, {$set: {active: false}}, { multi: true });
+        } else {
+            throw Meteor.Error(403, "Invalid permissions.");
+        }
+    },
+    addAlert: function(description, priority) {
+        if (isAdmin()) {
+            if (description.length > 0 && description.length < 400) {
+                var username = Meteor.user().profile.username;
+                if (["danger", "warning", "success", "primary"].indexOf(priority) === -1) {
+                    priority = "warning";
+                }
+                Alerts.insert({description: description, priority: priority, active: true, createdBy: username});
+                return true;
+            } else {
+                throw Meteor.Error(403, "Invalid description length.");
+            }
+        } else {
+            throw Meteor.Error(403, "Invalid permissions.");
+        }
+    },
     sendMessage: function(type, message) {
         if (Meteor.userId()) {
             var user = Meteor.user();