Browse Source

gui: Add one-off notifications that need to be acked

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3254
Audrius Butkevicius 9 years ago
parent
commit
08b5a7908f

+ 3 - 0
gui/default/index.html

@@ -248,6 +248,8 @@
       </div>
       </div>
     </div>
     </div>
 
 
+    <div ng-if="config && config.options && config.options.unackedNotificationIDs" ng-include="'syncthing/core/notifications.html'"></div>
+
     <!-- First regular row -->
     <!-- First regular row -->
 
 
     <div class="row">
     <div class="row">
@@ -672,6 +674,7 @@
   <script src="syncthing/core/localeService.js"></script>
   <script src="syncthing/core/localeService.js"></script>
   <script src="syncthing/core/modalDirective.js"></script>
   <script src="syncthing/core/modalDirective.js"></script>
   <script src="syncthing/core/naturalFilter.js"></script>
   <script src="syncthing/core/naturalFilter.js"></script>
+  <script src="syncthing/core/notificationDirective.js"></script>
   <script src="syncthing/core/pathIsSubDirDirective.js"></script>
   <script src="syncthing/core/pathIsSubDirDirective.js"></script>
   <script src="syncthing/core/popoverDirective.js"></script>
   <script src="syncthing/core/popoverDirective.js"></script>
   <script src="syncthing/core/selectOnClickDirective.js"></script>
   <script src="syncthing/core/selectOnClickDirective.js"></script>

+ 21 - 0
gui/default/syncthing/core/notificationDirective.js

@@ -0,0 +1,21 @@
+angular.module('syncthing.core')
+    .directive('notification', function () {
+        return {
+            restrict: 'E',
+            scope: true,
+            transclude: true,
+            template: '<div class="row" ng-if="visible()"><div class="col-md-12" ng-transclude></div></div>',
+            link: function (scope, elm, attrs) {
+                scope.visible = function () {
+                    return scope.config.options.unackedNotificationIDs.indexOf(attrs.id) > -1;
+                }
+                scope.dismiss = function () {
+                    var idx = scope.config.options.unackedNotificationIDs.indexOf(attrs.id);
+                    if (idx > -1) {
+                        scope.config.options.unackedNotificationIDs.splice(idx, 1);
+                        scope.saveConfig();
+                    }
+                }
+            }
+        };
+});

+ 16 - 0
gui/default/syncthing/core/notifications.html

@@ -0,0 +1,16 @@
+<!--
+<notification id='exampleNotification'>
+  <div class="panel panel-warning">
+    <div class="panel-heading"><h3 class="panel-title"><span class="fa fa-exclamation-circle"></span><span translate>Notice</span></h3></div>
+    <div class="panel-body">
+      <p translate>This is an example notification. ID of the notification should be appended to Options.UnackedNotificationIDs of the config.</p>
+    </div>
+    <div class="panel-footer">
+      <button type="button" class="btn btn-sm btn-default pull-right" ng-click="dismiss()">
+        <span class="fa fa-check"></span>&nbsp;<span translate>OK</span>
+      </button>
+      <div class="clearfix"></div>
+    </div>
+  </div>
+</notification>
+-->

+ 3 - 0
lib/config/config.go

@@ -176,6 +176,9 @@ func (cfg *Configuration) prepare(myID protocol.DeviceID) error {
 	if cfg.Options.AlwaysLocalNets == nil {
 	if cfg.Options.AlwaysLocalNets == nil {
 		cfg.Options.AlwaysLocalNets = []string{}
 		cfg.Options.AlwaysLocalNets = []string{}
 	}
 	}
+	if cfg.Options.UnackedNotificationIDs == nil {
+		cfg.Options.UnackedNotificationIDs = []string{}
+	}
 
 
 	// Prepare folders and check for duplicates. Duplicates are bad and
 	// Prepare folders and check for duplicates. Duplicates are bad and
 	// dangerous, can't currently be resolved in the GUI, and shouldn't
 	// dangerous, can't currently be resolved in the GUI, and shouldn't

+ 3 - 0
lib/config/optionsconfiguration.go

@@ -40,6 +40,7 @@ type OptionsConfiguration struct {
 	AlwaysLocalNets         []string `xml:"alwaysLocalNet" json:"alwaysLocalNets"`
 	AlwaysLocalNets         []string `xml:"alwaysLocalNet" json:"alwaysLocalNets"`
 	OverwriteRemoteDevNames bool     `xml:"overwriteRemoteDeviceNamesOnConnect" json:"overwriteRemoteDeviceNamesOnConnect" default:"false"`
 	OverwriteRemoteDevNames bool     `xml:"overwriteRemoteDeviceNamesOnConnect" json:"overwriteRemoteDeviceNamesOnConnect" default:"false"`
 	TempIndexMinBlocks      int      `xml:"tempIndexMinBlocks" json:"tempIndexMinBlocks" default:"10"`
 	TempIndexMinBlocks      int      `xml:"tempIndexMinBlocks" json:"tempIndexMinBlocks" default:"10"`
+	UnackedNotificationIDs  []string `xml:"unackedNotificationID" json:"unackedNotificationIDs"`
 
 
 	DeprecatedUPnPEnabled  bool     `xml:"upnpEnabled,omitempty" json:"-"`
 	DeprecatedUPnPEnabled  bool     `xml:"upnpEnabled,omitempty" json:"-"`
 	DeprecatedUPnPLeaseM   int      `xml:"upnpLeaseMinutes,omitempty" json:"-"`
 	DeprecatedUPnPLeaseM   int      `xml:"upnpLeaseMinutes,omitempty" json:"-"`
@@ -56,5 +57,7 @@ func (orig OptionsConfiguration) Copy() OptionsConfiguration {
 	copy(c.GlobalAnnServers, orig.GlobalAnnServers)
 	copy(c.GlobalAnnServers, orig.GlobalAnnServers)
 	c.AlwaysLocalNets = make([]string, len(orig.AlwaysLocalNets))
 	c.AlwaysLocalNets = make([]string, len(orig.AlwaysLocalNets))
 	copy(c.AlwaysLocalNets, orig.AlwaysLocalNets)
 	copy(c.AlwaysLocalNets, orig.AlwaysLocalNets)
+	c.UnackedNotificationIDs = make([]string, len(orig.UnackedNotificationIDs))
+	copy(c.UnackedNotificationIDs, orig.UnackedNotificationIDs)
 	return c
 	return c
 }
 }

+ 1 - 0
lib/model/model.go

@@ -2191,6 +2191,7 @@ func (m *Model) CommitConfiguration(from, to config.Configuration) bool {
 	from.Options.URUniqueID = to.Options.URUniqueID
 	from.Options.URUniqueID = to.Options.URUniqueID
 	from.Options.ListenAddresses = to.Options.ListenAddresses
 	from.Options.ListenAddresses = to.Options.ListenAddresses
 	from.Options.RelaysEnabled = to.Options.RelaysEnabled
 	from.Options.RelaysEnabled = to.Options.RelaysEnabled
+	from.Options.UnackedNotificationIDs = to.Options.UnackedNotificationIDs
 	// All of the other generic options require restart. Or at least they may;
 	// All of the other generic options require restart. Or at least they may;
 	// removing this check requires going through those options carefully and
 	// removing this check requires going through those options carefully and
 	// making sure there are individual services that handle them correctly.
 	// making sure there are individual services that handle them correctly.