Johannes Zellner 11 лет назад
Родитель
Сommit
c544a5fad7
5 измененных файлов с 84 добавлено и 4 удалено
  1. 3 0
      app.js
  2. 2 1
      bower.json
  3. 32 1
      public/index.html
  4. 24 0
      public/index.js
  5. 23 2
      src/things.js

+ 3 - 0
app.js

@@ -22,6 +22,9 @@ router.del ('/api/things/:id', things.del);
 
 router.get ('/api/tags', things.getTags);
 
+router.post('/api/settings', things.settingsSave);
+router.get ('/api/settings', things.settingsGet);
+
 app
     .use(json({ strict: true })) // only parse objects and arrays
     .use(serveStatic(__dirname + '/public'))

+ 2 - 1
bower.json

@@ -19,6 +19,7 @@
     "angular": "~1.4.8",
     "bootstrap": "~3.3.6",
     "bootstrap-material-design": "~0.5.2",
-    "angular-marked": "~1.0.1"
+    "angular-marked": "~1.0.1",
+    "mdi": "~1.3.41"
   }
 }

+ 32 - 1
public/index.html

@@ -5,9 +5,12 @@
 
 <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
 
+<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons"/>
+
 <link rel="stylesheet" href="/bootstrap/dist/css/bootstrap.min.css"/>
 <link rel="stylesheet" href="/bootstrap-material-design/dist/css/bootstrap-material-design.min.css"/>
 <link rel="stylesheet" href="/bootstrap-material-design/dist/css/ripples.min.css"/>
+<link rel="stylesheet" href="/mdi/css/materialdesignicons.min.css" media="all" type="text/css"/>
 
 <script type="text/javascript" src="/jquery/dist/jquery.min.js"></script>
 <script type="text/javascript" src="/bootstrap/dist/js/bootstrap.min.js"></script>
@@ -23,7 +26,7 @@
 
 </head>
 
-<body ng-controller="MainController">
+<body ng-controller="MainController" ng-style="{'background-image':'url(' + settings.backgroundUrl + ')'}">
 
 <div class="modal fade" id="modalAdd">
   <div class="modal-dialog">
@@ -43,11 +46,39 @@
   </div>
 </div>
 
+<div class="modal fade" id="modalSettings">
+  <div class="modal-dialog">
+    <div class="modal-content">
+      <div class="modal-header">
+        <button type="button" class="close">×</button>
+        <h4 class="modal-title">Settings</h4>
+      </div>
+      <div class="modal-body">
+        <form class="form-horizontal">
+          <div class="form-group">
+            <label for="inputBackgroundImage" class="col-sm-2 control-label">Background</label>
+            <div class="col-sm-10">
+              <input type="text" class="form-control" id="inputBackgroundImage" ng-model="settings.backgroundUrl" placeholder="url">
+            </div>
+          </div>
+        </form>
+      </div>
+      <div class="modal-footer">
+        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
+        <button type="button" class="btn btn-success" ng-click="saveSettings()">Save</button>
+      </div>
+    </div>
+  </div>
+</div>
+
 <div class="container main">
   <div class="row">
     <div class="col-md-2 col-md-offset-5">
         <button class="btn btn-raised btn-block btn-success" data-toggle="modal" data-target="#modalAdd">Add</button>
     </div>
+    <div class="col-md-1 col-md-offset-3">
+      <button class="btn btn-default btn-fab" data-toggle="modal" data-target="#modalSettings"><i class="mdi mdi-dots-horizontal"></i></button>
+    </div>
   </div>
   <div class="row">
     <div class="col-md-6 col-md-offset-3">

+ 24 - 0
public/index.js

@@ -22,6 +22,10 @@ app.controller('MainController', function ($scope, $http, $timeout) {
         content: ''
     };
 
+    $scope.settings = {
+        backgroundUrl: ''
+    };
+
     $scope.addFilterTag = function (tag) {
         var hashed = '#' + tag.name;
 
@@ -81,9 +85,29 @@ app.controller('MainController', function ($scope, $http, $timeout) {
         });
     };
 
+    $('#modalSettings').on('hidden.bs.modal', function () {
+        $scope.fetchSettings();
+    });
+
+    $scope.saveSettings = function () {
+        $http.post('/api/settings', { settings: $scope.settings }, {}).then(function (result) {
+            $('#modalSettings').modal('hide');
+        }, function (result) {
+            console.error('error:', result);
+        });
+    };
+
+    $scope.fetchSettings = function () {
+        $http.get('/api/settings', {}).then(function (result) {
+            angular.extend($scope.settings, result.data.settings);
+        }, function (result) {
+            console.error('error:', result);
+        });
+    };
 
     $scope.fetchThings();
     $scope.fetchTags();
+    $scope.fetchSettings();
 
     $timeout(function () {
         $.material.init();

+ 23 - 2
src/things.js

@@ -15,11 +15,13 @@ exports = module.exports = {
     get: get,
     add: add,
     del: del,
-    getTags: getTags
+    getTags: getTags,
+    settingsSave: settingsSave,
+    settingsGet: settingsGet
 };
 
 var databaseUrl = process.env.MONGODB_URL || 'mongodb://127.0.0.1:27017/guacamoly';
-var g_db, g_things, g_tags;
+var g_db, g_things, g_tags, g_settings;
 
 function sanitize(data) {
     data = data.replace(/##/g, data);
@@ -72,6 +74,7 @@ function init(callback) {
         g_db = db;
         g_things = db.collection('things');
         g_tags = db.collection('tags');
+        g_settings = db.collection('settings');
 
         callback(null);
     });
@@ -155,3 +158,21 @@ function getTags(req, res, next) {
         next(new HttpSuccess(200, { tags: result }));
     });
 }
+
+function settingsSave(req, res, next) {
+
+    console.log('settings', req.body)
+
+    g_settings.update({ type: 'frontend' }, { $set: req.body.settings }, { upsert:true }, function (error) {
+        if (error) return next(new HttpError(500, error));
+        next(new HttpSuccess(202, {}));
+    });
+}
+
+function settingsGet(req, res, next) {
+    g_settings.find({ type: 'frontend' }).toArray(function (error, result) {
+        console.log(error, result);
+        if (error) return next(new HttpError(500, error));
+        next(new HttpSuccess(200, { settings: result[0] || {} }));
+    });
+}