You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
2.0 KiB

  1. 'use strict';
  2. angular.module('app.newmodel', ['ngRoute'])
  3. .config(['$routeProvider', function($routeProvider) {
  4. $routeProvider.when('/newmodel', {
  5. templateUrl: 'views/newmodel/newmodel.html',
  6. controller: 'NewModelCtrl'
  7. });
  8. }])
  9. .controller('NewModelCtrl', function($scope, $rootScope, $http, toastr) {
  10. $scope.file = {};
  11. $scope.upload = function() {
  12. console.log("upload model");
  13. var formdata = new FormData();
  14. formdata.append("file", $scope.file);
  15. //add the file to ipfs
  16. /*$http({
  17. url: ipfs_url + 'add',
  18. method: "POST",
  19. headers: {
  20. "Content-Type": undefined
  21. },
  22. data: formdata
  23. })
  24. .then(function(data) {
  25. console.log("data: ");
  26. console.log(data.data);
  27. toastr.success("Model added to IPFS");
  28. },
  29. function(data) {
  30. console.log(data);
  31. toastr.error("Error adding Model to IPFS");
  32. });*/
  33. //add the data to userdata
  34. $http({
  35. url: clienturl + 'model',
  36. method: "POST",
  37. headers: {
  38. "Content-Type": undefined
  39. },
  40. data: $scope.model
  41. })
  42. .then(function(data) {
  43. console.log("data: ");
  44. console.log(data.data);
  45. window.location="/";
  46. toastr.success("Model uploaded");
  47. },
  48. function(data) {
  49. console.log(data);
  50. });
  51. };
  52. })
  53. .directive('fileModel', ['$parse', function($parse) {
  54. //directive code from https://www.tutorialspoint.com/angularjs/angularjs_upload_file.htm
  55. return {
  56. restrict: 'A',
  57. link: function(scope, element, attrs) {
  58. var model = $parse(attrs.fileModel);
  59. var modelSetter = model.assign;
  60. element.bind('change', function() {
  61. scope.$apply(function() {
  62. modelSetter(scope, element[0].files[0]);
  63. });
  64. });
  65. }
  66. };
  67. }]);