Problems saving a firebase database with angularjs - javascript

i've been using Firebase for a couple of months now, and it's been great along with angularjs and anfularfire, before i explain the problem, let me give you a fast background: i am currently using different controllers for an app that is meant for users to register plant species and to use them as items to create an interactive garden. In order to save the database from any controller, i stored the reference into the $scope
var rootRef = firebase.database().ref();
$scope.database = $firebaseObject(rootRef)
so when i want to make a change or add an object, i do it like this:
$scope.example_function = function(i){//supposing 'i' is a string
$scope.element[e] = i //supposing that 'e' contains a string
$scope.database.$save()
}
Sometimes this works, other times it just doesn't save the firebase, specially when editing existing objects inside the database or adding an element to an specific object. It's really frustrating because it doesn't throw an error or something, i even tried deleting the path i wanted to change and then storing it again with the new info. Also i tried with local references to the database in each controller, but nope... Anyone knows how else can i make this work?
Also. I am pretty sure the connection between the database and the app is fine, i got to store lots of species by now, the problem is when i want to edit the info from the species or add an url to get an image.

I don't think it's a good idea to bind your entire database to a the scope. It will be extremely hard to scale.
Remember that when you request for a ref and send it to $firebaseObject it will register to change events and this will start sync of your entire database which might potentially be huge.
For the issues you're experiencing, it looks like you're binding the database reference to a database property of $scope but in your example_function you're applying values to an element property. So maybe the fix you're looking for is something like:
function example_function(i) {
$scope.database.element = i;
$scope.database.$save();
}

Related

Using JS Object Based Multidimensional Arrays to Collect, Store, and View Data in a PDF Form

I have an interactive PDF form created in Acrobat that employs a multidimensional object to collect, store, and populate form fields used to view the data. The form serves as a password manager to view individual password records whereby I have recently completed the lookup record page view that works like a charm. The only issue I've run into thus far is my inability to delete a record selected in the lookup view in which event I initially thought I'd be able to use the JS array.splice() method to simply delete a line item in the object array that stores the data for the particular record I want to delete. Come to learn that the script used to create the object that stores the data still remains inside the form whereby literally nothing has changed. Upon further study, I am inclined to believe that the form is essentially serving as a window to view the information stored in the object and for whatever reason invoking a script using the JS slice() method has no effect whatsoever on the script that created the object to begin with. Hence, in order to make this work, it appears I need to be able to rewrite/replace the script minus the object property/s that hold the data for the record to be deleted. Sorry for the novel. Any comments or suggestions regarding this subject matter are most appreciated. Thank you ahead of time.
Created a script using the JS splice() method in a futile attempt to remove data from an object used to collect and store data inside an interactive PDF form.
From Adobe's Docs:
You can use the Document JavaScript dialog box to add, edit, or delete scripts in your current document.
To open the dialog box, choose Tools > JavaScript > Document JavaScript.
Here https://helpx.adobe.com/uk/acrobat/using/add-debug-javascript.html
I've never used Adobe Acrobat, but if you need to edit a script in a PDF, that's probably where to get at it.
If you post the script's code, someone might be able to help you. It's almost impossible to get an answer to any question without posting code.
I apologize regarding my initial post as I knew little to nothing at the time regarding how to create and use an object literal in which event I have since learned how to use an object literal along with its methods to add, delete, and edit key-value pairs of an object literal. I was then able to resolve all my issues in using an Acrobat PDF form as a front end along with a hidden text field using JSON to convert a JS data object for organizing and storing my form data as a string. The script to accomplish this task is as follows:
dsFld =getField("dataSrc");// call getField method used to obtain the
stored JS object as a JSON string
oVendors = JSON.parse(dsFld.value);//Parse the JSON string to manipulate
the JS data object
btnDel=getField("btn.del");
var oFld;// create var oFld for later use
var oPassData = oVendors[event.value];
if(oPassData){// script to populate PDF form fields
//walk members to fill fields
for(var nNm in oPassData){
// skip fields that don't exist on form
oFld = this.getField("inf." + nNm);
if(oFld)
oFld.value = oPassData[nNm];// script to populate associated form
fields
}
In looking back, I am sorry for any inconvenience posed by my initial post.

How to use Firebase in all documents?

My firebase is setup and initialized in my index.html, but then I can only use it there. Is there any way to use it on all documents?
It is set up in my index page, and then I use the data base and JQuery on a separate JS file to manipulate things also in that index page. I am doing similar things on another HTML page but when I call a function, it doesn't do anything/can't get the data. I thought I should initialize the database on that page too (within script tags of course, just copy/paste the code to initialize), and that also doesn't do anything. I also tried initializing it within the JS code as well, which seems to be the most intuitive thing to do, and that doesn't work either.
I initialize the database with the following:
var firebaseConfig = {...}
firebase.initializeApp(firebaseConfig);
var db = firebase.firestore();
Then just below, I can call a function in the JS and it uses the database information. But when I call a function in another HTML doc, it won't use the database.
I have initialized it in the JS file itself before, and that got me what I wanted but I can't do it again for some reason.
Once you navigate from one page to the next, you browser pretty much forgets anything from the previous page. This means that you will need to include Firebase into any page where you use it.
Firebase is often used in so-called single-page applications, which are implemented as a single real page, but emulate many application screens within that page. That way they only have to include/load Firebase once, but can still show multiple screens to the user. If you're interested in this approach, I recommend looking into some common single-page application frameworks, such as Angular, React, and Vue.

Tracking/Storing a variable across views with AngularJS

I am coding a pretty simple app that allows users to make certain selections and receive a random quote based on their selections. I have a pretty good idea on how to actually produce the quote but am stuck on how to track user selections until they get to the final view/page.
Specifically, my question is, how do I go about storing the user's selections in a variable or an array in a way that I can use it both on the last page and update it from any page for the quote generation? I haven't been using Angular for that long but what I've tried so far is making a service that includes an array for storing variables and then using directives on the buttons to update the array but this seems messy in the end with so many selections and it doesn't actually work right now.
Any and all suggestions or resources on how to achieve what I want are greatly appreciated <3
Defined this in my app.js
myApp.value('selection', {
first: "first choice here",
second: "second choice here"
});
And this in the controllers, updating the 'selection' based on the current view/ctrl along with the obvious necessary dependency injection
selection.first = "updated choice";

How to define Matrix/Link/Cross Table joins in BreezeJS Metadata?

I'm trying to get breeze working with hand generated Metadata, but I can't seem to find documentation covering navigation properties through matrix tables.
the data model is:
Organization
PK:OrganizationID
User
PK:UserID
The table that joins them is:
User_Organization
PK:UserOrganizationID
FK:OrganizationID
FK:UserID
When I retrieve an Organization I want it to have a property "users" which contains an array of User objects.
How do I define this and specify the matrix table in Breeze Metadata, seeing as User does not have an organizationID?
** update
My primary problem is that I'm linking Breeze to Sequelize, so I need to be able to manage this all through the metadata if possible. The first answer below from #Jeremy-Danyow solves the problem with client side code, but I'm looking for a way to present the final object graph to breeze as part of the metadata.
I think this question might be a duplicate of Many-to-many relations in Breeze. There is useful information in the answer there as well as the comments on the answer.
That said, I want to propose a work-around for this part of your question:
When I retrieve an Organization I want it to have a property "users" which contains an array of User objects.
If you were to configure your metadata the supported way you could add a read-only "users" property to your organization entity like this:
function Organization() { }
Organization.prototype.users = function () {
return this.userOrganizations().map(function(userOrganization) { return userOrganization.user() });
};
store.registerEntityTypeCtor('Organization', Organization);
This uses the "Add methods to the constructor" approach documented here.
Edit
Sounds like breeze-sequelize support is in the works and will be released soon. See here and here. If you can afford to wait a little bit you'll have less friction getting this going.

Netsuite: How to edit or update a record?

I am a newbie at NetSuite scripting. It looks like a normal EDIT or UPDATE function is not at all normal in the Netsuite. There are APIs for creating and deleting record like nlapiCreateRecord and nlapiDeleteRecord, but nowhere in the documentation I could find the way to edit and update the existing record. I have restrictions on using PHP.
I have created a custom TFC customer form (server side js), which should be able to fetch the data and update if required. I have been able to fetch the records as of now, but please tell me how to update an existing record?
To be a little more precise, use nlapiLoadRecord to fetch the record from the database. Set the fields as needed. Use nlapiSubmitRecord to save it.
Untested code off the top of my head:
var record = nlapiLoadRecord('record_type_goes_here', internal_id_of_record_goes_here);
record.setFieldValue('field_internal_id_goes_here', 'value to set goes here);
nlapiSubmitRecord(record);
Fill in the appropriate values where needed.
For the benefit of anyone looking at this question who is concerned with performance, it is much more efficient to use
nlapiSubmitField(type, id, fields, values, doSourcing)
If you know exactly what you are updating. This is both faster than submitRecord, and avoids the often significant overhead of loading the record first.
The function used to edit an existing record is nlapiSubmitRecord. See definition here http://suitecoder.appspot.com/static/api.html

Categories

Resources