Inset data in firebase realtime database with react-native - react-native

I am using Firebase Realtime Database in my react-native project. I want to save the data in below formate
Images
Category 1
Image:
"/9j/4AAQSkZJRgABAQAASABIAAD/4QBYRXhpZgAATU0AKgA...",
"/9j/4AAQSkZJRgABAQAASABIAAD/4QBYRXhpZgAATU0AKgA..."
Category 2
Image:
"/9j/4AAQSkZJRgABAQAASABIAAD/4QBYRXhpZgAATU0AKgA..."
I want to store data depend upon categories. if I select category 1 the data is overwriting the old once, but I want to add without overwriting the previous data.
Is it possible to do so?
sample code
firebase.database().ref('Images/'+this.state.selectedValue).set({
Image: this.state.imageSource,
}).then(() =>{
alert('saved')
}).catch((error) =>{
alert(JSON.stringify(error))
})

You are adding the new data to the old key so it is replacing it. You need to add a new key for every object like given below.
Images:{
Category 1:[{image1: "/9j/4AAQSkZJRgABAQAASABIAAD/4QBYRXhpZgAA..."},image2:{"jmehyrjwrjewrghwe"} ],
Category 2:[ "/9j/4AAQSkZJRgABAQAASABIAAD/4QBYRXhpZgAATU0AKgA..." ],image2:{"jmehyrjwrjewrghwe"} }
Then it will work

Related

Podio API JS - Update relationship field of a Item

Using NodeJS, I am trying to update relationship field which link to another app (contacts-leads). I have try all combination but still getting error. I think I have the necessary data to post, app_id, item_id, external_id..etc. I need help with forming JSON structure.
p.request('put','item/<Item_Id>/value', data)
var data {....}
app_id:'<app_id>'
value:'<value>' (value is the app_item_id of the link to application; that is the number in URL)
app_item_id: '<app_item_id>'
external_id:'<external_id>'
I was able to update non-relationship field without problem.
Thanks
Well, going to answer my own question. That will work for single app link, not sure about multiple ones.
data = {
"<external_id>": {
"apps": [{"app_id": <app_id>}],
"value: <app_item_id>
}
}

Mobx-state-tree create form with types.identifier field on model

I've started using mobx-state-tree recently and I have a practical question.
I have a model that has a types.identifier field, this is the database id of the resource and when I query for existing stuff it gets populated.
When I am creating a new instance, though, following the example that Michel has on egghead, I need to pass an initial id to my MyModel.create() on initial state, however, this ID will only be known once I post the creation to the API and get the resulting created resource.
I have searched around for a simple crud example using mobx-state-tree but couldn't find one (suggestions?).
What is the best practice here? Should I do a `MyModel.create({ id: 'foobar' }) and weed it out when I post to the API (and update the instance once I get the response from the API)?
This is a limitation of mobx-state-tree's current design. Identifiers are immutable.
One strategy I've seen to get around this issue is to store your persistence layer's id in a separate field from your types.identifier field. You would then use a library like uuid to generate the types.identifier value:
import { v4 } from "node-uuid"
const Box = types
.model("Box", {
id: types.identifier,
name: "hal",
x: 0,
y: 0
})
const box = Box.create({ 'hal', 10, 10, id: v4() })

Storing custom application configurations on cumulocity

Is there a way to store custom application configurations on the Cumulocity backend through the c8y.sdk? I would like to store a JSON with configuration information specific to an application created using the the smart app toolkit.
You can save settings at the tenant by using c8ySettings,
BUT you have a limitation of 256 characters per value.
I'm struggling with the same problem of storing larger plugin configurations without any success.
I asked about this from cumulocity support and they said it is possible to store custom JSON under managedobjects because at the moment they dont support storing JSON to database otherwise.
So you will need "create" or "admin" rights to inventory to be able to create new managedobject. You can store values like this:
var userSettings = {
type: 'userDashboardSettings',
yourSetting: somesetting,
id: settingsId
};
c8yInventory.save(userSettings).then(function(){
//do something
});
then you can search this newly created managedobject like this:
c8yInventory.list({
type: 'userDashboardSettings',
owner: id,
pageSize: 2
}).then(function (settings) { //do something }
So this way I was for example able to save user specific settings.
To find user dashboard settings do GET to: https://yourdomain.com/inventory/managedObjects/?type=userDashboardSettings&owner=IDHERE
To Delete managedObject do DELETE to: https://yourdomain.com/inventory/managedObjects/IDHERE
To see all managedObjects do GET: https://yourdomain.com/inventory/managedObjects
Type and user are important, this is how you find the managedobject.

ExtJS4 - Cross-store model deletion: Removing a model from a store by creating a model and setting it's ID

I am building a web application and I have a Grid Panel A who has Store A that uses a Model A. When the user clicks a certain entry E with an ID and clicks the delete button, what I want to happen is to get Store B then remove the entry with the same ID as the selected entry E.
Basically, what I'm trying to do is some sort of "cross-store" model deletion. The model from Store A gets selected, but the entry from Store B gets deleted.
Here's what I've done so far:
var userStore = Ext.getStore('borrowerListStore'); //this is Store B
var model = Ext.ModelManager.create({
}, 'myAppLicationName.model.borrowerList'); //this is Model B
model.set("ID", personID); //person id here is the ID of Entry E selected earlier
Ext.getBody().mask('Starting Client Delete...');
userStore.remove(model); //I remove the model from the store
//then I sync the store
userStore.sync({
success: function(batch){
Ext.getBody().unmask();
console.log('delete user details success');
},
failure: function(batch){
Ext.getBody().unmask();
console.log('delete user details failure');
}
});
However, I am stuck on the masking screen.
I also tried loading the store first as such before I remove then sync the store:
userStore.load({
callback: function() {
userStore.remove(model);
}
});
However, I still got stuck on the loading screen.
Is there any way to do a cross-store model deletion based on a model property? I know that I can get Store B then iterate through the models and then remove the one whose ID matches the ID of what the user selected. My issue with that is if I have a lot of records in my store, it would take a lot of time to search through those.
Okay I'm an idiot.
I did something like:
userStore.getProxy().extraParams = {
selectedUserID: personID
};
and I had a if-else handling part in the php if selectedUserID was passed, I'd query the database using that in my Where clause so I'd end up with 1 entry.

Data structure to use in Sencha Touch similar to Vector in Blackberry

I am a beginner to sencha Touch, basically i am a blackberry developer. Currently we are migrating our application to support Sencha Touch 1.1. Now i have some business solutions like i want to store the selected values in the local database. I mean i have multiple screens where, Once the user selects a value in each of the screen the data should save in the below following format.
[{'key1': "value1", 'key2': "value2", 'key3': "value3" ,'key4': "value4", 'key5': "value5"}]
1. First, the values need to be saved in key value pairs
2. The keys should play the role of primary key, key shouldn't be duplicated.
3. Should be available till the application life cycle or application session, don't need to save the data permanently.
I have come across the concepts like LocalStorageProxy, JsonStore and some others. I don't understand which one i can use for my specific requirements.
May be my question is bit more confusing. I have achieved the same using vector, in Blackberry Java so any data structure similar to this could help me. Need the basic operations like
Create
Add
Remove
Remove all
Fetch elements based on key
Please suggest me some samples or some code snapshots, which may help me to achieve this.
Edit: 1
I have done the changes as per #Ilya139 's answer. Now I am able to add the data with key,
// this is my Object declared in App.js
NSDictionary: {},
// adding the data to object with key
MyApp.NSDictionary['PROD'] = 'SONY JUKE BOX';
//trying to retrieve the elements from vector
var prod = MyApp.NSDictionary['PROD'];
Nut not able to retrieve the elements using the above syntax.
If you don't need to save the data permanently then you can just have a global object with the properties you need. First define the object like this:
new Ext.Application({
name: 'MyApp',
vectorYouNeed: {},
launch: function () { ...
Then add the key-value pairs to the object like this
MyApp.vectorYouNeed[key] = value;
And fetch them like this
value = MyApp.vectorYouNeed[key];
Note that key is a string object i.e. var key='key1'; and value can be any type of object.
To remove one value MyApp.vectorYouNeed[key] = null; And to remove all of them MyApp.vectorYouNeed = {};