Update service notifications

This commit is contained in:
perploug
2013-10-20 19:58:44 +02:00
parent 2b8c566e65
commit 9000ece7d1
11 changed files with 152 additions and 88 deletions

View File

@@ -1,19 +0,0 @@
/**
* @ngdoc service
* @name umbraco.resources.publishedContentResource
* @description service to retrieve published content from the umbraco cache
*
*
**/
function publishedContentResource($q, $http, umbRequestHelper) {
//TODO: Why do we have this ? If we want a URL why isn't it just on the content controller ?
//the factory object returned
return {
};
}
angular.module('umbraco.resources').factory('publishedContentResource', publishedContentResource);

View File

@@ -26,43 +26,60 @@ angular.module('umbraco.services')
var nArray = [];
function add(item) {
angularHelper.safeApply($rootScope, function () {
//add a colon after the headline if there is a message as well
if (item.message) {
item.headline += ":";
if(item.message.length > 200) {
item.sticky = true;
}
}
var service = {
//we need to ID the item, going by index isn't good enough because people can remove at different indexes
// whenever they want. Plus once we remove one, then the next index will be different. The only way to
// effectively remove an item is by an Id.
item.id = String.CreateGuid();
nArray.push(item);
if(!item.sticky) {
$timeout(function() {
var found = _.find(nArray, function(i) {
return i.id === item.id;
});
/**
* @ngdoc method
* @name umbraco.services.notificationsService#add
* @methodOf umbraco.services.notificationsService
*
* @description
* Lower level api for adding notifcations, support more advanced options
* @param {Object} item The notification item
* @param {String} item.headline Short headline
* @param {String} item.message longer text for the notication, trimmed after 200 characters, which can then be exanded
* @param {String} item.type Notification type, can be: "success","warning","error" or "info"
* @param {String} item.url url to open when notification is clicked
* @param {Boolean} item.sticky if set to true, the notification will not auto-close
* @returns {Object} args notification object
*/
if (found) {
var index = nArray.indexOf(found);
nArray.splice(index, 1);
}
add: function(item) {
angularHelper.safeApply($rootScope, function () {
}, 7000);
}
//add a colon after the headline if there is a message as well
if (item.message) {
item.headline += ":";
if(item.message.length > 200) {
item.sticky = true;
}
}
return item;
});
}
//we need to ID the item, going by index isn't good enough because people can remove at different indexes
// whenever they want. Plus once we remove one, then the next index will be different. The only way to
// effectively remove an item is by an Id.
item.id = String.CreateGuid();
return {
nArray.push(item);
if(!item.sticky) {
$timeout(function() {
var found = _.find(nArray, function(i) {
return i.id === item.id;
});
if (found) {
var index = nArray.indexOf(found);
nArray.splice(index, 1);
}
}, 7000);
}
return item;
});
},
/**
* @ngdoc method
@@ -123,9 +140,8 @@ angular.module('umbraco.services')
* @returns {Object} notification object
*/
success: function (headline, message) {
return add({ headline: headline, message: message, type: 'success', time: new Date() });
},
return service.add({ headline: headline, message: message, type: 'success', time: new Date() });
},
/**
* @ngdoc method
* @name umbraco.services.notificationsService#error
@@ -140,7 +156,7 @@ angular.module('umbraco.services')
* @returns {Object} notification object
*/
error: function (headline, message) {
return add({ headline: headline, message: message, type: 'error', time: new Date() });
return service.add({ headline: headline, message: message, type: 'error', time: new Date() });
},
/**
@@ -158,7 +174,7 @@ angular.module('umbraco.services')
* @returns {Object} notification object
*/
warning: function (headline, message) {
return add({ headline: headline, message: message, type: 'warning', time: new Date() });
return service.add({ headline: headline, message: message, type: 'warning', time: new Date() });
},
/**
@@ -176,7 +192,7 @@ angular.module('umbraco.services')
* @returns {Object} notification object
*/
info: function (headline, message) {
return add({ headline: headline, message: message, type: 'info', time: new Date() });
return service.add({ headline: headline, message: message, type: 'info', time: new Date() });
},
/**
@@ -233,4 +249,6 @@ angular.module('umbraco.services')
return nArray;
}
};
return service;
});

View File

@@ -20,6 +20,32 @@ function legacyJsLoader(assetsService, umbRequestHelper) {
}
angular.module('umbraco.services').factory('legacyJsLoader', legacyJsLoader);
/**
* @ngdoc function
* @name umbraco.services.updateChecker
* @function
*
* @description
* used to check for updates and display a notifcation
*/
function updateChecker($http, umbRequestHelper) {
return {
/** Called to load in the legacy tree js which is required on startup if a user is logged in or
after login, but cannot be called until they are authenticated which is why it needs to be lazy loaded. */
check: function() {
return umbRequestHelper.resourcePromise(
$http.get(
umbRequestHelper.getApiUrl(
"updateCheckApiBaseUrl",
"GetCheck")),
'Failed to retreive update status');
}
};
}
angular.module('umbraco.services').factory('updateChecker', updateChecker);
/**
* @ngdoc service
* @name umbraco.services.umbPropertyEditorHelper

View File

@@ -14,7 +14,8 @@
.border-radius(@baseBorderRadius);
}
.alert,
.alert h4 {
.alert h4,
.alert a {
// Specified for the h4 to prevent conflicts of changing @headingsColor
color: @warningText;
}

View File

@@ -254,7 +254,7 @@
@successBorder: transparent;
@infoText: @white;
@infoBackground: @purple;
@infoBackground: @blue;
@infoBorder: transparent;
// SD: Had to duplicate the above but prefix with 'form' with the bootstrap original colors

View File

@@ -8,7 +8,7 @@
* The main application controller
*
*/
function MainController($scope, $location, $routeParams, $rootScope, $timeout, $http, $log, notificationsService, userService, navigationService, legacyJsLoader) {
function MainController($scope, $location, $routeParams, $rootScope, $timeout, $http, $log, notificationsService, userService, navigationService, legacyJsLoader, updateChecker) {
var legacyTreeJsLoaded = false;
@@ -57,10 +57,8 @@ function MainController($scope, $location, $routeParams, $rootScope, $timeout, $
//when a user logs out or timesout
$scope.$on("notAuthenticated", function() {
$scope.authenticated = null;
$scope.user = null;
});
//when a user is authorized setup the data
@@ -79,6 +77,21 @@ function MainController($scope, $location, $routeParams, $rootScope, $timeout, $
$scope.authenticated = data.authenticated;
$scope.user = data.user;
updateChecker.check().then(function(update){
if(update && update !== "null"){
if(update.type !== "Nones"){
var notification = {
headline: "Update available",
message: "Click to download",
sticky: true,
type: "info",
url: update.url
};
notificationsService.add(notification);
}
}
});
//if the user has changed we need to redirect to the root so they don't try to continue editing the
//last item in the URL
if (data.lastUserId && data.lastUserId !== data.user.id) {

View File

@@ -2,11 +2,13 @@
<ul>
<li ng-repeat="notification in notifications" class="alert alert-block alert-{{notification.type}}">
<a class='close' ng-click="removeNotification($index)" prevent-default href='#'>&times;</a>
<a class='close' ng-click="removeNotification($index)" prevent-default href>&times;</a>
<strong>{{notification.headline}}</strong>
<span ng-bind-html="notification.message"></span>
<a ng-href="{{notification.url}}" target="_blank">
<strong>{{notification.headline}}</strong>
<span ng-bind-html="notification.message"></span>
</a>
</li>
</ul>
</div>

View File

@@ -140,6 +140,10 @@ namespace Umbraco.Web.Editors
"memberTypeApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl<MemberTypeController>(
controller => controller.GetAllTypes())
},
{
"updateCheckApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl<UpdateCheckController>(
controller => controller.GetCheck())
},
}
},
{
@@ -165,28 +169,7 @@ namespace Umbraco.Web.Editors
return JavaScript(ServerVariablesParser.Parse(d));
}
[HttpGet]
public UpgradeCheckResponse UpdateChecker()
{
//PP: The statehelper is obsolete, but there are NO directions on what to use instead, so keeping it here...
var updChkCookie = new global::umbraco.BusinessLogic.StateHelper.Cookies.Cookie("UMB_UPDCHK", GlobalSettings.VersionCheckPeriod);
string updateCheckCookie = updChkCookie.HasValue ? updChkCookie.GetValue() : "";
if (GlobalSettings.VersionCheckPeriod > 0 && String.IsNullOrEmpty(updateCheckCookie) && Security.CurrentUser.UserType.Alias == "admin")
{
updChkCookie.SetValue("1");
var check = new global::umbraco.presentation.org.umbraco.update.CheckForUpgrade();
var result = check.CheckUpgrade(UmbracoVersion.Current.Major,
UmbracoVersion.Current.Minor,
UmbracoVersion.Current.Build,
UmbracoVersion.CurrentComment);
return new UpgradeCheckResponse(result.UpgradeType.ToString(), result.Comment, result.UpgradeUrl);
}
return null;
}
private IEnumerable<Dictionary<string, string>> GetTreePluginsMetaData()
{

View File

@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;
using Umbraco.Core.Configuration;
using Umbraco.Web.Models;
namespace Umbraco.Web.Editors
{
public class UpdateCheckController : UmbracoAuthorizedJsonController
{
[HttpGet]
public UpgradeCheckResponse GetCheck()
{
//PP: The statehelper is obsolete, but there are NO directions on what to use instead, so keeping it here...
var updChkCookie = new global::umbraco.BusinessLogic.StateHelper.Cookies.Cookie("UMB_UPDCHK", GlobalSettings.VersionCheckPeriod);
string updateCheckCookie = updChkCookie.HasValue ? updChkCookie.GetValue() : "";
if (GlobalSettings.VersionCheckPeriod > 0 && String.IsNullOrEmpty(updateCheckCookie) && Security.CurrentUser.UserType.Alias == "admin")
{
updChkCookie.SetValue("1");
var check = new global::umbraco.presentation.org.umbraco.update.CheckForUpgrade();
var result = check.CheckUpgrade(UmbracoVersion.Current.Major,
UmbracoVersion.Current.Minor,
UmbracoVersion.Current.Build,
UmbracoVersion.CurrentComment);
return new UpgradeCheckResponse(result.UpgradeType.ToString(), result.Comment, result.UpgradeUrl);
}
return null;
}
}
}

View File

@@ -9,10 +9,12 @@ using Umbraco.Core.Configuration;
namespace Umbraco.Web.Models
{
[DataContract(Name = "upgrade", Namespace = "")]
public class UpgradeCheckResponse
{
[DataMember(Name = "type")]
public string Type { get; set; }
[DataMember(Name = "comment")]
public string Comment { get; set; }

View File

@@ -312,6 +312,7 @@
<Compile Include="Editors\MembershipProviderValidationFilterAttribute.cs" />
<Compile Include="Editors\MemberTypeController.cs" />
<Compile Include="Editors\TagExtractor.cs" />
<Compile Include="Editors\UpdateCheckController.cs" />
<Compile Include="MembershipProviderExtensions.cs" />
<Compile Include="Models\ChangingPasswordModel.cs" />
<Compile Include="Models\ContentEditing\ModelWithNotifications.cs" />