var post1 = $http({
method: "POST",
url: "/Home/GetunAvailableDates",
dataType: 'json',
data: sub1,
headers: { "Content-Type": "application/json" }
});
var a = [];
post.then(function (d) {
if (d) {
for (var i = 0; i < d.data.length; i++) {
a.push(d.data[i].valueOf(Text).Text)
}
}
console.log("success");
}, function (d) {
$window.alert("Oops!! Something went wrong!!!!.");
});
this.selectedDates = a;
I'm currently working in mvc project.
I'm using AngularJs datepicker for my booking page. I need to disable dates which booking is unavailable.
I retrieve dates from database as list inside my booking.js file
My problem is how can bind that list of dates to angular datepicker. I tried so many ways but result was not good. guys help me how can i do that using angular.
Related
I did the application on the sample from this lesson. Here, using DRF, a list of all added games is displayed on the page. I would really like to learn how to write a simple form of adding a new record to the database (two fields: title and description [as in the example]).
With js, I'm not very familiar with so far, so I do not know which side to get close to solving the problem.
$scope.saveUser = function(event) {
postForm({ id: 0 }, $('#FormName'), $scope, function(data) {
})
}
function postForm(postInfo, form, $scope, callback,) {
var postData = new FormData(form.get(0));
$.each(postInfo, function(key, value) {
postData.append(key, value);
});
$.ajax({
type: form.attr('method'),
url: form.attr('action'),
data: postData,
cache: false,
dataType: 'json',
processData: false,
contentType: false,
headers: {
"X-CSRFToken": app.getStorage("csrftoken")
},
beforeSend: function() {
$('#loading-image').show();
},
complete: function() {
$('#loading-image').hide();
if(typeof saveButtonId !== typeof undefined) {
$('#'+saveButtonId).removeAttr('disabled');
}
},
success: function(data) {
},
error: function(data) {
//
}
});
};
you'd be updating code in your mysite/backend folder to have some incoming route to insert data into django db using some serializer
sorry I don't have more specific details, but just wanted to convey the general idea
Here's some more information on Django serializers: http://www.django-rest-framework.org/api-guide/serializers/
another tutorial on adding an additional route to django could help
Hi I am developing one web api application using angularjs. I am doing one small crud operation. I am not able to hit to controller when debugging. Below is my controll.js code.
$scope.EditSubscriber = function (sub) {
var servCall = UserCreation.getSubsbyID(sub.user_id);
servCall.then(function (d) {
$scope.user_email = d.user_email,
$scope.user_password = d.user_password
}, function (error) {
console.log('Oops! Something went wrong while fetching the data.')
});
}
Below is my service.js code.
this.getSubsbyID = function (user_id) {
return $http({
method: 'get',
data: JSON.stringify(user_id),
url: 'api/User_Creation/' + user_id,
contentType: "application/json"
});
}
This is my controller code.
public IEnumerable<Noor_Users> Get(int user_id)
{
return entityObject.Noor_Users.Where(a => a.user_id == user_id).AsEnumerable();
}
I am not getting any error but I am not able to hit breakpoint in controller. May I know where I am doing wrong? Thank you all.
I have an application made with .NET core framework and pure html in the front end. I was using AJAX to post and get data.
I am new to Angular and decided to convert the front end of the application to Angular for learning purposes.
For Example, I have a button that will change the state of employees from 'Billed' to 'Available' state. The ID for available state is defined in the back end and it is '1'.
//MOVE TO BENCH BUTTON CLICK
$(document).ready(function()
{
var allVals = [];
$("#MoveToBench").click(function()
{
$('input:checkbox:checked').each(function () {
allVals.push($(this).val());
});
for (i = 0;i<allVals.length;i++){
PostBenchList(allVals[i])
}
function PostBenchList(entityId) {
var data = 'entityID='.concat(entityId).concat('&nextStateId=1');
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "http://localhost:1783/api/Workflow?"+data,
data: data,
dataType: "text",
success: function (data) {
location.reload();
alert("Successfully added the selected Employees to TalentPool");
},
fail: function (error) {
Console.Log(error);
}
})
}
});
});
The above code is taking an array of entityID's as input. For the Angular application, the array is not required as only one entity ID will be passed.
The API controller in the backend is :
// POST api/values
[HttpPost]
public void Post(int entityId, int nextStateId)
{
JObject jsonObject = JObject.Parse(System.IO.File.ReadAllText("Config.Json"));
string jsonFile = jsonObject.GetValue("WorkfowJsonFileLocation").ToString();
var nextState = _stateServices.Get(nextStateId);
var handler = new WorkflowHandler(nextState, jsonFile, _entityServices, 1, _stateServices, _subStateServices, _appServices);
handler.PerformAction(entityId);
}
The above code worked for me and it would change the state ID of the employee(EntityID)to 1(nextStateId)
Now I have a button in AngularJS and I want it to do the same action. How would I achieve this? As I am still in the procedure of learning, I don't have a clue how to do this. Can anyone help me to achieve this? This would help me to learn and do all similar buttons.
Thank You.
You can use ng-click and call a function to post the data,
HTML:
<button ng-click="PostData()">
Click to POST
</button>
Controller:
app.controller('PostController',['$scope',function($scope)
{
$scope.sendPost = function() {
var data = $.param({
json: JSON.stringify({
name: $scope.newName
})
});
$http.post("/echo/json/", data).success(function(data, status) {
$scope.hello = data;
})
}
}]);
DEMO APP
at first time ng-grid show my data very well, but when user change input form and then application get new data via ajax call, ng-grid data doesn't updated.
$scope.gridOptions = {
data: 'gridData',
plugins: [new ngGridCsvExportPlugin()],
showFooter: true
};
$scope.gridData = [];
$http({
method: 'POST',
url: '/risk',
data: criteria,
headers: {
'Content-Type': 'application/json'
}
}).success(function (response) {
var gridData = [];
response.list.forEach(function (e, i) {
if (criteria.measureType == 'risk')
gridData.push({'risk': e.riskFactor, "bank": e.bank});
else if (criteria.measureType == 'centrality')
gridData.push({"centrality": e.centrality, "bank": e.bank});
});
}
$scope.gridData = angular.copy(gridData);
$scope.$apply()
});
neigher ng-grid doesn't update data nor AngularJS/ng-grid - Updating array with splice doesn't updates UI couldn't any help.
what is my mistake. tanhks
I had similar problem with Ui grid. We are using broadcast for updating the grid data as soon we change or want to refresh data
The following is a GET request I am making to Parse.com's RESTful API. I want to structure the request to only retrieve records that have been received today.
$http({
method: "GET",
url: "https://api.parse.com/1/classes/Order",
headers: {
"X-Parse-Application-Id": PARSE_CREDENTIALS.APP_ID,
"X-Parse-REST-API-Key": PARSE_CREDENTIALS.REST_API_KEY,
"Content-Type": "application/json"
},
params: {
// WHAT DO I PUT HERE?
createdAt: /* greater than 8am today, less than or equal to current time */
}
})
After reading from the Parse API docs about Query Constraints, I've modified the $http GET. However, it still returns all Orders.
var startDate = new Date();
var currentTime = new Date().getTime();
startDate.setHours(8);//set time to 8 am.
$http({ method: "GET",
url: "https://api.parse.com/1/classes/Order",
headers: {
"X-Parse-Application-Id": PARSE_CREDENTIALS.APP_ID,
"X-Parse-REST-API-Key": PARSE_CREDENTIALS.REST_API_KEY,
"Content-Type": "application/json"
},
params: {
where: {
"createdAt": { "$gte": startDate, "$lte": currentTime }
}
}
})
EDIT 1: Upon structuring my get request like so: I receive a 400 HTTP error, containing the following:
code: 107
error: "invalid date {1.433264918052e+12}"
EDIT 2 (SOLVED): I've solved the issue. After resolving the structure of the params property, I learned that the Parse API expects an ISO format DateTime. So, my final version looks like this:
var startDate = new Date().toISOString();
var currentTime = new Date().getTime().toISOString();
startDate.setHours(8);//set time to 8 am.
var deferred = $q.defer();
$http({ method: "GET",
url: "https://api.parse.com/1/classes/Order",
headers: {
"X-Parse-Application-Id": PARSE_CREDENTIALS.APP_ID,
"X-Parse-REST-API-Key": PARSE_CREDENTIALS.REST_API_KEY,
"Content-Type": "application/json"
},
params: {
where: {
"createdAt": { "$gte": startDate, "$lte": currentTime }
}
}
})
If someone would like to take this opportunity and give a thorough explanation, I would be happy to give them the answer (e.g. what benefit is there for Parse to use ISO over standard Unix epoch time?).
You can pass the from and to dates timestamp to pass a range of date. Try something like this.
var startDate = new Date();
startDate.setHours(8);//set time to 8 am.
$http({
method: "GET",
url: "https://api.parse.com/1/classes/Order",
headers: {
"X-Parse-Application-Id": PARSE_CREDENTIALS.APP_ID,
"X-Parse-REST-API-Key": PARSE_CREDENTIALS.REST_API_KEY,
"Content-Type": "application/json"
},
params: {
createdFrom: startDate.getTime(),
createdTo: new Date().getTime()
}
});
On the server side you can convert the timestamp to date object to pass it to DB stored proc or query.
Realized that I posted the answer in the question a long time ago. Updating this with an official answer for posterity.
I've solved the issue. After resolving the structure of the params property, I learned that the Parse API expects an ISO format DateTime. So, my final version looks like this:
var startDate = new Date().toISOString();
var currentTime = new Date().getTime().toISOString();
startDate.setHours(8);//set time to 8 am.
var deferred = $q.defer();
$http({ method: "GET",
url: "https://api.parse.com/1/classes/Order",
headers: {
"X-Parse-Application-Id": PARSE_CREDENTIALS.APP_ID,
"X-Parse-REST-API-Key": PARSE_CREDENTIALS.REST_API_KEY,
"Content-Type": "application/json"
},
params: {
where: {
"createdAt": { "$gte": startDate, "$lte": currentTime }
}
}
})