My JS file has become very big I want to break into some modules.Could
anyone please help me out and please tell me how to do this.
Here is my code.
app.js
var app = angular.module("app", ["xeditable","checklist-model"]);
app.run(function(editableOptions) {
editableOptions.theme = 'bs3'; // bootstrap3 theme. Can be also 'bs2',
'default'
});
//Cluster Installation
app.controller('Ctrl', function($scope,$filter,$http) {
$scope.master2=[];
$scope.master3='';
$scope.add_service ={
type:'',
hostname: '',
dependent:'',
cluster_vms:'',
instance_count:'',
add_Service:{
servicename: '',
version: '',
os:'',
flavor_ref:'',
imgage_id:'',
instance_type:'',
packages:[],
count:1
}
};
$scope.user = {
installation_type:'cluster',
add_services:[]
};
//OS Selection
$scope.oslist = [];
$scope.loadOS = function() {
var url="http://apps.web2labs.net/api/v2.0/infra/os";
var httpRequest = $http({
method: 'GET',
url: url
}).success(function(data, status) {
$scope.oslist1 = data;
angular.forEach($scope.oslist1,function(o){
var obj = {};
obj.value = o.os_type;
obj.imgid = o.image_id;
obj.text = o.os_type;
$scope.oslist.push(obj)
})
}).error(function(data,status){
alert("Failed to load the OS list");
console.log("Failed to load "+status);
})
};
$scope.loadOS();
$scope.showOS = function() {
var selected = $filter('filter')($scope.oslist, {value:
$scope.add_service.add_Service.os});
$scope.add_service.add_Service.imgage_id=selected[0].imgid;
return ($scope.add_service.add_Service.os && selected.length) ?
selected[0].text : 'Select OS';
};
//InsatanceType Selection
$scope.ilist = [];
$scope.loadInstanceTypes = function() {
var url="http://apps.web2labs.net/api/v2.0/infra/instancetypes";
var httpRequest = $http({
method: 'GET',
url: url
}).success(function(data, status) {
$scope.ilist1 = data;
console.log(angular.toJson($scope.ilist1))
angular.forEach($scope.ilist1,function(i){
var obj = {};
obj.value = i;
obj.text = i;
$scope.ilist.push(obj);
console.log(angular.toJson($scope.ilist))
})
}).error(function(data,status){
alert("Failed to load the InstanceType list");
console.log("Failed to load "+status);
})
};
$scope.loadInstanceTypes();
$scope.showInstanceType = function() {
var selected = $filter('filter')($scope.ilist, {value:
$scope.add_service.add_Service.instance_type});
return ($scope.add_service.add_Service.instance_type && selected.length) ?
selected[0].text : 'Select InstanceType';
};
//Package Selection
$scope.pkgs = [];
$scope.loadPackages = function() {
var url="http://apps.web2labs.net/api/v2.0/infra/packages";
var httpRequest = $http({
method: 'GET',
url: url
}).success(function(data, status) {
$scope.pkgs1 = data;
console.log(angular.toJson($scope.pkgs1))
angular.forEach($scope.pkgs1,function(p){
var obj = {};
obj.value = p;
obj.text = p;
$scope.pkgs.push(obj);
console.log(angular.toJson($scope.pkgs))
})
}).error(function(data,status){
alert("Failed to load the Package list");
console.log("Failed to load "+status);
})
};
$scope.loadPackages();
$scope.showPackages = function() {
var selected = [];
angular.forEach($scope.pkgs, function(p) {
if($scope.add_service.add_Service.packages.indexOf(p.value) >= 0){
selected.push(p.text);
}
});
return selected.length ? selected.join(', ') : 'Select Packages';
};
//Add Function
$scope.add = function() {
$scope.list = angular.copy($scope.add_service);
$scope.user.add_services.push($scope.list);
$scope.add_service.add_Service.os = angular.copy($scope.master3);
$scope.add_service.add_Service.packages = angular.copy($scope.master2);
$scope.add_service.add_Service.instance_type = angular.copy($scope.master3);
$scope.add_service.add_Service.servicename = angular.copy($scope.master3);
$scope.add_service.add_Service.version = angular.copy($scope.master3);
$scope.add_service.add_Service.imgage_id = angular.copy($scope.master3);
$scope.add_service.add_Service.flavor_ref = angular.copy($scope.master3);
$scope.add_service.type = angular.copy($scope.master3);
$scope.add_service.hostname = angular.copy($scope.master3);
$scope.add_service.dependent = angular.copy($scope.master3);
$scope.add_service.cluster_vms = angular.copy($scope.master3);
$scope.add_service.instance_count = angular.copy($scope.master3);
};
//Submit Function
$scope.submit = function() {
console.log(angular.toJson($scope.user));
var url="http://apps.web2labs.net/api/v2.0/infra/services/cluster";
var httpRequest = $http({
method: 'POST',
url: url ,
headers: {
'Content-Type': 'application/json'
},
data: angular.toJson($scope.user)
}).success(function(data, status) {
alert("JSON successfully registered");
$("#dbsuccess1").html("<div class='alert alert-success
alert-dismissable'><i class='fa fa-check'></i><button type='button'
class='close' data-dismiss='alert' aria-hidden='true'>x</button>Posted
successfully!</div>");
}).error(function(data,status){
alert("Failed to load the JSON");
console.log("Failed to load "+status);
$("#dbsuccess1").html("<div class='alert alert-danger alert-dismissable'><i
class='glyphicon glyphicon-exclamation-sign'></i><button type='button'
class='close' data-dismiss='alert' aria-hidden='true'>x</button>Error in
posting data to server!</div>");
})
};
//Remove Function
$scope.removeUser = function(index) {
alert("Are you sure to remove");
$scope.user.add_services.splice(index, 1);
console.log(JSON.stringify($scope.user.add_services));
};
});
//Single Installation
app.controller('Ctrl1', function($scope,$filter,$http) {
$scope.serviceList=[];
$scope.master2=[];
$scope.master3='';
$scope.add_services ={
service_name: '',
version: '',
OS:'',
flavor_ref:'',
image_id:'',
instance_type:'',
packages:[],
count:1
};
$scope.user = {
installation_type:'single',
hostname: '',
instance_count:'',
add_service:''
};
//OS Selection
$scope.oslist = [];
$scope.loadOS = function() {
var url="http://apps.web2labs.net/api/v2.0/infra/os";
var httpRequest = $http({
method: 'GET',
url: url
}).success(function(data, status) {
$scope.oslist1 = data;
angular.forEach($scope.oslist1,function(o){
var obj = {};
obj.value = o.os_type;
obj.imgid = o.image_id;
obj.text = o.os_type;
$scope.oslist.push(obj)
})
}).error(function(data,status){
alert("Failed to load the OS list");
console.log("Failed to load "+status);
})
};
$scope.loadOS();
$scope.showOS = function() {
var selected = $filter('filter')($scope.oslist, {value:
$scope.add_services.OS});
$scope.add_services.image_id=selected[0].imgid;
return ($scope.add_services.OS && selected.length) ? selected[0].text :
'Select OS';
};
//InstanceType Selection
$scope.ilist = [];
$scope.loadInstanceTypes = function() {
var url="http://apps.web2labs.net/api/v2.0/infra/instancetypes";
var httpRequest = $http({
method: 'GET',
url: url
}).success(function(data, status) {
$scope.ilist1 = data;
//console.log(angular.toJson($scope.ilist1))
angular.forEach($scope.ilist1,function(i){
var obj = {};
obj.value = i;
obj.text = i;
$scope.ilist.push(obj);
//console.log(angular.toJson($scope.ilist))
})
}).error(function(data,status){
alert("Failed to load the InstanceType list");
console.log("Failed to load "+status);
})
};
$scope.loadInstanceTypes();
$scope.showInstanceType = function() {
var selected = $filter('filter')($scope.ilist, {value:
$scope.add_services.instance_type});
return ($scope.add_services.instance_type && selected.length) ?
selected[0].text : 'Select InstanceType';
};
//Package Selection
$scope.pkgs = [];
$scope.loadPackages = function() {
var url="http://apps.web2labs.net/api/v2.0/infra/packages";
var httpRequest = $http({
method: 'GET',
url: url
}).success(function(data, status) {
$scope.pkgs1 = data;
//console.log(angular.toJson($scope.pkgs1))
angular.forEach($scope.pkgs1,function(p){
var obj = {};
obj.value = p;
obj.text = p;
$scope.pkgs.push(obj);
//console.log(angular.toJson($scope.pkgs))
})
}).error(function(data,status){
alert("Failed to load the Package list");
console.log("Failed to load "+status);
})
};
$scope.loadPackages();
$scope.showPackages = function() {
var selected = [];
angular.forEach($scope.pkgs, function(p) {
if ($scope.add_services.packages.indexOf(p.value) >= 0) {
selected.push(p.text);
}
});
return selected.length ? selected.join(', ') : 'Select Packages';
};
//Submit Function
$scope.submit = function() {
$scope.list = angular.copy($scope.add_services);
$scope.user.add_service = angular.copy($scope.list);
$scope.serviceList = angular.copy($scope.user);
$scope.add_services.OS = angular.copy($scope.master3);
$scope.add_services.packages = angular.copy($scope.master2);
$scope.add_services.instance_type = angular.copy($scope.master3);
$scope.add_services.service_name = angular.copy($scope.master3);
$scope.add_services.version = angular.copy($scope.master3);
$scope.add_services.image_id = angular.copy($scope.master3);
$scope.add_services.flavor_ref = angular.copy($scope.master3);
$scope.user.hostname = angular.copy($scope.master3);
$scope.user.instance_count = angular.copy($scope.master3);
console.log(angular.toJson($scope.serviceList));
var url="http://apps.web2labs.net/api/v2.0/infra/services/single";
var httpRequest = $http({
method: 'POST',
url: url ,
headers: {
'Content-Type': 'application/json'
},
data: angular.toJson($scope.serviceList)
}).success(function(data, status) {
alert("JSON successfully registered");
$("#dbsuccess").html("<div class='alert alert-success
alert-dismissable'><i class='fa fa-check'></i><button type='button'
class='close' data-dismiss='alert' aria-hidden='true'>x</button>Posted
successfully!</div>");
}).error(function(data,status){
alert("Failed to load the JSON");
console.log("Failed to load "+status);
$("#dbsuccess").html("<div class='alert alert-danger alert-dismissable'><i
class='glyphicon glyphicon-exclamation-sign'></i><button type='button'
class='close' data-dismiss='alert' aria-hidden='true'>x</button>Error in
posting data to server!</div>");
})
};
});
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.