controller.js file (with some failed console.logs):
angular.module("umbraco").controller("MapGeneratorController", function ($scope, userService, WorldGeneratorService, $http, $sce, postingLog) {
var vm = this;
vm.title = "Map Generator";
userService.getCurrentUser().then(function (user) {
vm.title = "Welcome " + user.name + ", to the map generator!";
});
$scope.generating = function () {
console.log("henlo");
$scope.info = "Getting all, please wait...";
WorldGeneratorService.generateAll().success(function (data) {
console.log(data);
$scope.result = data;
$scope.info = "Done!";
console.log(data);
});
};
});
angular.module("umbraco.resources").factory("WorldGeneratorService", function ($http) {
return {
generateAll: function () {
return $http.get("backoffice/Api/Admin/GenerateWorld");
}
};
});
controller in which I want the button click to lead me to eventually:
namespace UmbracoBasic.Web.Controllers
{
public class AdminController : UmbracoAuthorizedController
{
// GET: Admin
[HttpGet]
public string GenerateWorld()
{
return "henlo";
}
[HttpPost]
public string GenerateWorlds()
{
return "henlo";
}
}
}
So I get the custom dashboard in my admin view of umbraco, I see the button and everything else from the .html file but when I press the button absolutely nothing happens, I've tried some different ways in my .js file but none of them work (it won't even trigger the console.logs).
As of now I'm at a loss and I'm having trouble finding any similar problems (I find several posts about custom dashboards but none about this specific button onclick issue im having).
I'm not saying 'this is it'... but usually if I'm using the
var vm = this;
approach then I'll define the functions I want to call from the view on the vm rather than the $scope eg:
//have properties on the vm to track status
vm.status = {
isLoading: false,
statusMessage: ''
};
//have properties on the vm to store the data returned
vm.data = {
result: [],
hasResults: false
};
//declare the method on the vm
vm.generating = generating;
//define the function
function generating() {
console.log("henlo");
vm.status.isLoading = true;
vm.status.statusMessage = 'Getting all, please wait...';
WorldGeneratorService.generateAll().success(function (data) {
console.log(data);
vm.status.isLoading = false;
vm.status.statusMessage = 'Done!';
vm.data.result = data;
vm.data.hasResults = true;
console.log(data);
});
};
Hi Marc, thanks for the reply! Unfortunately this still does nothing when I press my button..im not really sure why vm.title gets printed in my tool but not the button function..
and if you just add an alert('hello'); to the start of the controller - are you getting that appearing...
One of the things that completely bamboozled me when I started with Umbraco and AngularJS, is the monumental level of 'caching' that occurs, so for ages I was stuck, pressing Ctrl-F5 and nothing working, whatever I tried, but then I found, that there is an option in Chrome to 'not cache' when developer tools was open.
And with Developer Tools open, if you right-click the 'refresh' icon in the browser there is a further menu item called 'Empty cache and hard reload'... and that is what I've found always forces a fresh load of my angularJS implementation...
so it may be worth just trying that alert message and a complete refresh to rule out that caching is the culprit!
Ye I usually rightclick hard-refresh and clear cache on each refresh (habit by now lol). At the start of the controller I put the vm.title string which I can see work..I could try with alert also, but what would that tell me? Why would title work and not anything else?
good point, so not caching then! and yes right click clear cache and full reload becomes very instinctive...
... I've spotted something else, but it depends a little on which console.logs are not being written out...
Your controller that you are making a GET request to inherits from UmbracoAuthorizedController, but this is an MVC controller, I think you need to inherit from UmbracoAuthorizedApiController
The UmbracoAuthorizedController won't be routed via backoffice/Api/Admin/GenerateWorld
Only if you inherit from UmbracoAuthorizedApiController....
but you shoudl see the first console.log when the generating() method is called before the api request, and you should see a 404 when the Get request is made... so maybe this isn't the problem now (but will be the problem when you get this far... :-))
The issue turned out to be that umbraco cached everything and that somehow prevented any action from the button click to be ignored..felt slightly dumb when I realized this I must say :D
But thank you for all the help along they of me discovering the cause of the issue, much appreciated!
Custom Dashboard button click won't trigger my function
I am currently trying to make a custom backoffice dashboard tool which all went well until I was trying to trigger the "generate" button on click.
Package.Manifest:
.html file:
controller.js file (with some failed console.logs):
controller in which I want the button click to lead me to eventually:
So I get the custom dashboard in my admin view of umbraco, I see the button and everything else from the .html file but when I press the button absolutely nothing happens, I've tried some different ways in my .js file but none of them work (it won't even trigger the console.logs).
As of now I'm at a loss and I'm having trouble finding any similar problems (I find several posts about custom dashboards but none about this specific button onclick issue im having).
Hi Isaiah
I'm not saying 'this is it'... but usually if I'm using the
var vm = this;
approach then I'll define the functions I want to call from the view on the vm rather than the $scope eg:
and then in your view on your button
regards
Marc
Hi Marc, thanks for the reply! Unfortunately this still does nothing when I press my button..im not really sure why vm.title gets printed in my tool but not the button function..
Hi Isaiah
are there any errors in the console?
and if you just add an alert('hello'); to the start of the controller - are you getting that appearing...
One of the things that completely bamboozled me when I started with Umbraco and AngularJS, is the monumental level of 'caching' that occurs, so for ages I was stuck, pressing Ctrl-F5 and nothing working, whatever I tried, but then I found, that there is an option in Chrome to 'not cache' when developer tools was open.
And with Developer Tools open, if you right-click the 'refresh' icon in the browser there is a further menu item called 'Empty cache and hard reload'... and that is what I've found always forces a fresh load of my angularJS implementation...
so it may be worth just trying that alert message and a complete refresh to rule out that caching is the culprit!
regards
marc
Hey Marc,
Ye I usually rightclick hard-refresh and clear cache on each refresh (habit by now lol). At the start of the controller I put the vm.title string which I can see work..I could try with alert also, but what would that tell me? Why would title work and not anything else?
Hi Isaiah
good point, so not caching then! and yes right click clear cache and full reload becomes very instinctive...
... I've spotted something else, but it depends a little on which console.logs are not being written out...
Your controller that you are making a GET request to inherits from UmbracoAuthorizedController, but this is an MVC controller, I think you need to inherit from UmbracoAuthorizedApiController
https://github.com/umbraco/Umbraco-CMS/blob/34e80d86e8c0b754f6b7a02e307f53cb32806bbe/src/Umbraco.Web/WebApi/UmbracoAuthorizedApiController.cs
The UmbracoAuthorizedController won't be routed via backoffice/Api/Admin/GenerateWorld
Only if you inherit from UmbracoAuthorizedApiController....
but you shoudl see the first console.log when the generating() method is called before the api request, and you should see a 404 when the Get request is made... so maybe this isn't the problem now (but will be the problem when you get this far... :-))
regards
Marc
The issue turned out to be that umbraco cached everything and that somehow prevented any action from the button click to be ignored..felt slightly dumb when I realized this I must say :D
But thank you for all the help along they of me discovering the cause of the issue, much appreciated!
sincerely, Isaiah
Glad it's all working! - pain when it's things like this, but I guess that is our developer lives through and through! - onto the next problem now!
I keep dev tools open when working in the backoffice with this enabled. It gets around the caching issue.
Oh ye, should start doing this more. Does this have the same effect as setting debug=true in web.config?
No debug=true is something different. It compiles the code/dlls in debug mode and generates pdbs allowing you to step through the code.
is working on a reply...