]> www.vanbest.org Git - motioneye-debian/commitdiff
added an update button
authorCalin Crisan <ccrisan@gmail.com>
Sun, 27 Oct 2013 09:29:45 +0000 (11:29 +0200)
committerCalin Crisan <ccrisan@gmail.com>
Sun, 27 Oct 2013 09:44:31 +0000 (11:44 +0200)
src/handlers.py
src/update.py
static/css/main.css
static/css/ui.css
static/js/main.js
static/js/ui.js
templates/main.html

index 81829aad6a263e7b4ecfdd115c1f474ad9b151be..b18e8b14dd045037f541494bac391beb085451c1 100644 (file)
@@ -33,9 +33,12 @@ class BaseHandler(RequestHandler):
         return data
     
     def render(self, template_name, content_type='text/html', **context):
+        import motioneye
+        
         self.set_header('Content-Type', content_type)
         
         context['USER'] = self.current_user
+        context['VERSION'] = motioneye.VERSION
         
         content = template.render(template_name, **context)
         self.finish(content)
@@ -512,13 +515,14 @@ class SnapshotHandler(BaseHandler):
     
     @BaseHandler.auth(prompt=False)
     def current(self, camera_id):
+        self.set_header('Content-Type', 'image/jpeg')
+        
         camera_config = config.get_camera(camera_id)
         if camera_config['@proto'] == 'v4l2':
             jpg = mjpgclient.get_jpg(camera_id)
             if jpg is None:
                 return self.finish()
         
-            self.set_header('Content-Type', 'image/jpeg')
             self.finish(jpg)
         
         else:
@@ -527,7 +531,6 @@ class SnapshotHandler(BaseHandler):
                     self.finish({})
                     
                 else:
-                    self.set_header('Content-Type', 'image/jpeg')
                     self.finish(jpg)
             
             remote.current_snapshot(
@@ -593,8 +596,15 @@ class UpdateHandler(BaseHandler):
         stable = self.get_argument('stable', default='false') == 'true'
         
         versions = update.get_all_versions(stable=stable)
-        
-        self.finish_json(versions)
+        current_version = update.get_version()
+        update_version = None
+        if versions and update.compare_versions(versions[-1], current_version) > 0:
+            update_version = versions[-1]
+
+        self.finish_json({
+            'update_version': update_version,
+            'current_version': current_version
+        })
 
     @BaseHandler.auth(admin=True)
     def post(self):
@@ -603,5 +613,5 @@ class UpdateHandler(BaseHandler):
         logging.debug('performing update to version %(version)s' % {'version': version})
         
         result = update.perform_update(version)
-
+        
         return self.finish_json(result)
index 961a000e920ba578a2d3d49cbb7e0e47d9adbc09..aafcbade8907133ac1399a5fdc5c2826934712c4 100644 (file)
@@ -40,10 +40,7 @@ def get_all_versions(stable=False):
         if stable:
             versions = [v for v in versions if v.count('.') == 1]
 
-        versions.sort()
-        
-        return ['master'] # TODO
-        return versions
+        return sorted(versions, cmp=compare_versions)
 
     except Exception as e:
         logging.error('could not get versions: %(msg)s' % {'msg': unicode(e)})
index 97e24516722b8f426922407377d391dc46be2889..c2ce5870dc0f49909c8c81334bec6503e771c2e7 100644 (file)
@@ -253,6 +253,28 @@ img.apply-progress {
     margin-top: 3px;
 }
 
+div.update-button {
+    position: relative;
+    width: 4em;
+    height: 1.5em;
+    line-height: 1.5em;
+    text-align: center;
+    margin: 2px 0px;
+    color: white;
+    font-size: 1em;
+    background-color: #317CAD;
+    border-radius: 3px;
+    transition: all 0.1s linear;
+}
+
+div.update-button:HOVER {
+    background-color: #3498db;
+}
+
+div.update-button:ACTIVE {
+    background-color: #317CAD;
+}
+
 div.settings-top-bar.open select.video-device {
     display: inline;
 }
index fefb05ae17e575b0e72dc8f4e45f149354c8fe5b..b9c6cc23bd55fc956578a945593a91c362e52165 100644 (file)
@@ -302,7 +302,7 @@ div.modal-container {
 }
 
 div.modal-title-bar {
-    height: 1.5em;
+    min-height: 1.5em;
     line-height: 1.5em;
     text-align: center;
     position: relative;
@@ -418,7 +418,7 @@ tr:HOVER span.help-mark {
     }
     
     div.modal-title-bar {
-        height: 2em;
+        min-height: 2em;
         line-height: 2em;
     }
     
index b0abe55db993fbe2517108896a2dd01ac613c8cd..037949b9e15f6c81c37777f48794bc05f625d597 100644 (file)
@@ -758,7 +758,7 @@ function doApply() {
         }
         
         if (data.reload) {
-            window.location.reload();
+            window.location.reload(true);
             return;
         }
         
@@ -805,6 +805,32 @@ function doRemCamera() {
     });
 }
 
+function doUpdate() {
+    showModalDialog('<div class="modal-progress"></div>');
+    ajax('GET', '/update/?stable=true', null, function (data) {
+        if (data.update_version == null) {
+            runAlertDialog('motionEye is up to date (current version: ' + data.current_version + ')');
+        }
+        else {
+            runConfirmDialog('New version available: ' + data.update_version + '. Update?', function () {
+                showModalDialog('<div class="modal-progress"></div>');
+                ajax('POST', '/update/?version=' + data.update_version, null, function (result) {
+                    if (result) {
+                        runAlertDialog('motionEye was successfully updated!', function () {
+                            window.location.reload(true);
+                        });
+                    }
+                    else {
+                        runAlertDialog('Update failed!', function () {
+                            window.location.reload(true);
+                        });
+                    }
+                });
+            });
+        }
+    });
+}
+
 
     /* fetch & push */
 
@@ -937,8 +963,8 @@ function pushPreview() {
 
     /* dialogs */
 
-function runAlertDialog(message) {
-    runModalDialog({title: message, buttons: 'ok'});
+function runAlertDialog(message, onOk) {
+    runModalDialog({title: message, buttons: 'ok', onOk: onOk});
 }
 
 function runConfirmDialog(message, onYes) {
@@ -1461,6 +1487,9 @@ $(document).ready(function () {
         }
     });
     
+    /* software update button */
+    $('div#updateButton').click(doUpdate);
+    
     /* prevent scroll events on settings div from propagating TODO this does not work */
     $('div.settings').mousewheel(function (e, d) {
         var t = $(this);
index a0f8a420480b55e79c66cb7c1ba1008254ba1d55..43a5d85815814c812bcd63d53455ccd57ac85bcd 100644 (file)
@@ -493,6 +493,12 @@ function showModalDialog(content, onClose) {
     var glass = $('div.modal-glass');
     var container = $('div.modal-container');
     
+    if (container.is(':animated')) {
+        return setTimeout(function () {
+            showModalDialog(content, onClose);
+        }, 100);
+    }
+    
     if (container.is(':visible')) {
         /* the modal dialog is already visible,
          * we just replace the content */
@@ -523,6 +529,12 @@ function hideModalDialog() {
     var glass = $('div.modal-glass');
     var container = $('div.modal-container');
     
+    if (container.is(':animated')) {
+        return setTimeout(function () {
+            hideModalDialog();
+        }, 100);
+    }
+    
     glass.animate({'opacity': '0'}, 200, function () {
         glass.css('display', 'none');
     });
@@ -576,11 +588,11 @@ function makeModalDialogButtons(buttonsInfo) {
         if (info.click) {
             var oldClick = info.click;
             info.click = function () {
+                hideModalDialog();
+                
                 if (oldClick() == false) {
                     return;
                 }
-                
-                hideModalDialog();
             };
         }
         else {
index 8c981e5df88bac8dc41b127951c6f024d26da153..e05fa399712cf923dfb88cc0ce3b9d7a95f51dd5 100644 (file)
@@ -32,6 +32,7 @@
         </div>
     </div>
     <div class="page">
+        {% if USER == 'admin' %}
         <div class="settings">
             <div class="settings-container">
                 <div class="settings-section-title"><input type="checkbox" class="styled section general" id="motionEyeSwitch">General Settings</div>
                         <td class="settings-item-value"><input type="password" class="styled general" id="normalPasswordEntry"></td>
                         <td><span class="help-mark" title="the password for the surveillance user">?</span></td>
                     </tr>
+                    <tr class="settings-item advanced-setting">
+                        <td colspan="100"><div class="settings-item-separator"></div></td>
+                    </tr>
+                    <tr class="settings-item advanced-setting">
+                        <td class="settings-item-label"><span class="settings-item-label">Current Version</span></td>
+                        <td class="settings-item-value"><span class="settings-item-label">{{VERSION}}</span></td>
+                        <td><span class="help-mark" title="checks for new versions and performs updates">?</span></td>
+                    </tr>
+                    <tr class="settings-item advanced-setting">
+                        <td class="settings-item-label"><span class="settings-item-label">Software Update</span></td>
+                        <td class="settings-item-value"><div class="button update-button" id="updateButton">Check</div></td>
+                        <td><span class="help-mark" title="checks for new versions and performs updates">?</span></td>
+                    </tr>
                 </table>
                 
                 <div class="settings-section-title"><input type="checkbox" class="styled section device" id="videoDeviceSwitch">Video Device</div>
                 </table>
             </div>
         </div>
+        {% endif %}
         <div class="page-container">
         </div>
         <div class="footer">