Bläddra i källkod

Worked on news.

KrisVos130 9 år sedan
förälder
incheckning
44a03965a9

+ 6 - 0
app/client/scripts/helpers.js

@@ -204,6 +204,12 @@ Template.queues.helpers({
     }
 });
 
+Template.news.helpers({
+    articles: function() {
+        return News.find().fetch().reverse();
+    }
+});
+
 Template.manageStation.helpers({
     songs: function () {
         var parts = location.href.split('/');

+ 1 - 0
app/client/scripts/main.js

@@ -21,6 +21,7 @@ Deps.autorun(function() {
     Meteor.subscribe("songs");
     Meteor.subscribe("alerts");
     Meteor.subscribe("rooms");
+    Meteor.subscribe("news");
     Meteor.subscribe("userData", Meteor.userId());
 });
 

+ 9 - 0
app/client/scripts/onRendered.js

@@ -50,6 +50,15 @@ Template.manageStation.onRendered(function() {
     });
 });
 
+Template.news.onRendered(function() {
+    if (rTimeInterval !== undefined) {
+        Meteor.clearInterval(rTimeInterval)
+    }
+    rTimeInterval = Meteor.setInterval(function() {
+        Session.set("time", new Date().getTime());
+    }, 10000);
+});
+
 Template.room.onRendered(function() {
     if (rTimeInterval !== undefined) {
         Meteor.clearInterval(rTimeInterval)

+ 17 - 26
app/client/templates/news.html

@@ -1,31 +1,22 @@
 <template name="news">
     {{> header}}
-    <main class="content-box">
-        <h3 class="black-text thin">News, Updates & Announcements</h3>
-        <ul class="collection">
-        <!--
-        {{#each chat}}
-        <li class="collection-item news-box">
-            <span class="news-title">{{title}}</span>
-            <hr>
-            <p class="news-content">{{content}}</p>
-            <p class="news-creator">Posted by: {{postBy}}</p>
-            <p class="news-postTime">{{timePostedAgo}}. ({{timePostedDate}})</p>
-        </li>
-        {{/each}}
-        -->
-
-        <!-- TEMP HARDCODED NEWS ARTICLE, soon you can add/remove news from the admin panel -->
-        <li class="collection-item news-box">
-            <span class="news-title">Welcome To Musare 2.0</span>
-            <hr>
-            <p class="news-content">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla rhoncus magna orci, tristique aliquam arcu ultricies non.
-              <br />Vivamus iaculis leo lectus. In quis nunc rhoncus nulla hendrerit pellentesque in nec ipsum. Curabitur facilisis enim nulla, sit amet dapibus lacus aliquet ut. Integer lacinia pharetra semper.
-              <br />Duis mattis varius egestas. Cras sit amet venenatis lacus. Curabitur ut maximus urna, vel pulvinar ex. Do It Work?!</p>
-            <p class="news-creator">Posted by: Johand</p>
-            <p class="news-postTime">5days ago. (5/01/2016)</p>
-        </li>
-        </ul>
+    <main class="content-box row">
+        <h3 class="black-text thin center">News</h3>
+            {{#each articles}}
+                <div class="card teal-text col m6 s12 l6 offset-m3 offset-l3">
+                    <div class="card-content">
+                        <span>{{title}}</span>
+                        <hr>
+                        <p class="flow-text" style="word-wrap:break-word;">
+                            {{content}}
+                        </p>
+                    </div>
+                    <div class="card-action">
+                        <span>Posted by: {{author}}.</span><br>
+                        <span>Created at: {{rtime time}}.</span>
+                    </div>
+                </div>
+            {{/each}}
     </main>
     {{> footer}}
 </template>

+ 2 - 1
app/database/collections.js

@@ -6,4 +6,5 @@ Chat = new Mongo.Collection("chat");
 Alerts = new Mongo.Collection("alerts");
 Deleted = new Mongo.Collection("deleted");
 Feedback = new Mongo.Collection("feedback");
-Songs = new Mongo.Collection("songs");
+Songs = new Mongo.Collection("songs");
+News = new Mongo.Collection("news");

+ 20 - 0
app/database/schemas.js

@@ -503,6 +503,25 @@ Schemas.Report = new SimpleSchema({
     }
 });
 
+Schemas.Article = new SimpleSchema({
+    "title": {
+        type: String,
+        label: "Article Title"
+    },
+    "content": {
+        type: String,
+        label: "Article Content"
+    },
+    "author": {
+        type: String,
+        label: "Article's Author"
+    },
+    "time": {
+        type: Date,
+        label: "Article's Create Date"
+    }
+});
+
 Rooms.attachSchema(Schemas.Room);
 Alerts.attachSchema(Schemas.Alert);
 Chat.attachSchema(Schemas.Chat);
@@ -512,3 +531,4 @@ Meteor.users.attachSchema(Schemas.User);
 Reports.attachSchema(Schemas.Report);
 Feedback.attachSchema(Schemas.Feedback);
 Songs.attachSchema(Schemas.FullSong);
+News.attachSchema(Schemas.Article);

+ 35 - 0
app/server/server.js

@@ -437,6 +437,10 @@ Meteor.publish("alerts", function () {
     return Alerts.find({active: true})
 });
 
+Meteor.publish("news", function () {
+    return News.find({})
+});
+
 Meteor.publish("userData", function (userId) {
     if (userId !== undefined) {
         return Meteor.users.find(userId, {fields: {"services.github.username": 1, "punishments": 1}})
@@ -935,6 +939,37 @@ Meteor.methods({
             return true;
         }
     },
+    createArticle: function(data) {
+        if (!isBanned() && isModerator()) {
+            var userId = Meteor.userId();
+            var requiredProperties = ["title", "content", "author"];
+            if (data !== undefined && Object.keys(data).length === requiredProperties.length) {
+                for (var property in requiredProperties) {
+                    if (data[requiredProperties[property]] === undefined) {
+                        throw new Meteor.Error(403, "Invalid data.");
+                    }
+                }
+                if (data.author === true) {
+                    data.author = Meteor.user().profile.username
+                } else {
+                    data.author = "A Musare Admin";
+                }
+                data.time =  new Date();
+                News.insert(data, function(err, res) {
+                    if (err) {
+                        console.log(err);
+                        throw err.sanitizedError;
+                    } else {
+                        return true;
+                    }
+                });
+            } else {
+                throw new Meteor.Error(403, "Invalid data.");
+            }
+        } else {
+            throw new Meteor.Error(403, "Invalid permissions.");
+        }
+    },
     addSongToQueue: function (songData) {
         if (Meteor.userId() && !isBanned()) {
             var userId = Meteor.userId();