Code Monkey home page Code Monkey logo

webix-firebase's Introduction

Firebase adapter for Webix UI

npm version

Library allows using Webix components with FireBase

Latest version will work with Webix 6.2+, if you are using an older version of Webix, you need to use version 0.5 of this package.

Citing the Firebase site:

When data changes, apps built with Firebase update instantly across every device -- web or mobile.

Firebase-powered apps work offline. Data is synchronized instantly when your app regains connectivity.

Firestore

Include Webix and Firebase files on the page

<!-- Webix -->
<script type="text/javascript" src="http://cdn.webix.com/edge/webix.js"></script>
<link rel="stylesheet" type="text/css" href="http://cdn.webix.com/edge/webix.css">
<!-- Webix-Firebase adapter -->
<script type="text/javascript" src="../codebase/webix-firestore.js"></script>
<!-- FireBase -->
<script src="https://www.gstatic.com/firebasejs/5.0.4/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/5.0.4/firebase-firestore.js"></script>

Create main firebase connection

firebase.initializeApp({
	apiKey: "YOU API KEY HERE",
	projectId: "webix-demo"
});

// create firebase connection, and assign it to webix
var db = firebase.firestore();
db.settings({ timestampsInSnapshots:true });

webix.firestore = db;

Init webix component, using "firebase->{reference}" as data url

webix.ui({
	id:"dtable",
	view:"datatable",
	autoConfig:true,

	// load data from "books" collection
	url: "firestore->books",
	// save data to "books" collection
	save:"firestore->books"
}

That is it.

Adding "url" property will enable data loading and automatic updates of component when data changed in the firebase.

Adding "save" property ensures that all changes in the datatable will be saved to the Firebase

Using FireBase references

Instead of using text url you can use firestore collections directly

firebase.initializeApp({
	apiKey: "YOU API KEY HERE",
	projectId: "webix-demo"
});

// create firebase connection, and assign it to webix
var db = firebase.firestore();
db.settings({ timestampsInSnapshots:true });

var proxy = webix.proxy("firestore", db.collection("books"));

webix.ui({
	view:"list",
	url: proxy,
	save: proxy
}););

Dynamic data loading

You can use "load" command to (re)load data in the component.

$$("dtable").clearAll();
$$("dtable").load("firestore->books");

or

$$("dtable").clearAll();
$$("dtable").load( webix.proxy("firestore", collection) );

Realtime Database

Include Webix and Firebase files on the page

<!-- Webix -->
<script type="text/javascript" src="http://cdn.webix.com/edge/webix.js"></script>
<link rel="stylesheet" type="text/css" href="http://cdn.webix.com/edge/webix.css">
<!-- Webix-Firebase adapter -->
<script type="text/javascript" src="../codebase/webix-firebase.js"></script>
<!-- FireBase -->
<script src="https://www.gstatic.com/firebasejs/5.0.4/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/5.0.4/firebase-database.js"></script>

Create main firebase connection

firebase.initializeApp({
  databaseURL: "https://webix-demo.firebaseio.com/"
});

// create firebase connection, and assign it to webix
webix.firebase = firebase.database();

Init webix component, using "firebase->{reference}" as data url

webix.ui({
	id:"dtable",
	view:"datatable",
	editable:true, editaction:"dblclick",
	columns:[{
		id:"name", editor:"text", fillspace:1
	},{
		id:"author", editor:"text", fillspace:1
	}],

	// load data from /books
	url: "firebase->books",
	// save data to /books
	save:"firebase->books"
}

That is it.

Adding "url" property will enable data loading and automatic updates of component when data changed in the firebase.

Adding "save" property ensures that all changes in the datatable will be saved to the Firebase

Using FireBase references

Instead of using text url you can use firebase references directly

firebase.initializeApp({
	databaseURL: "https://webix-demo.firebaseio.com/"
});
var db = firebase.database();
var proxy = webix.proxy("firebase", db.ref("books"));

webix.ui({
	view:"list",
	url: proxy,
	save: proxy
});

Dynamic data loading

You can use "load" command to (re)load data in the component.

$$("dtable").clearAll();
$$("dtable").load("firebase->books");

or

$$("dtable").clearAll();
$$("dtable").load( webix.proxy("firebase", ref) );

Sync api

Webix components have native sync api to sync data between components. The same api can be used with firebase

firebase.initializeApp({
	databaseURL: "https://webix-demo.firebaseio.com/"
});
webix.firebase = firebase.database();
var ref = webix.firebase.ref("books");

$$("dtable").sync(ref);

Working with Forms and Templates

Similar to data views, you can use "load" and "save" API while working with Forms

//form
$$("form").load("books/4");
...
$$("form").save();

//template
$$("template").load("books/4")

In some cases, it has sense to not load data correctly but bind form ( template ) to some other view or data collection

var data = new webix.DataCollection({
	url:"firebase->books",
	save:"firebase->books"
})
form.bind(data);
data.waitData.then(function(){
	//you need to use setCursor API to load some record from collection into a form
	data.setCursor("4");
})

or, the same for the datatable

webix.ui({
	view:"datatable", autoConfig:true, id:"d1", select:true,
	url:"firebase->books",
	save:"firebase->books"
});
form.bind("d1"); //selected row will be shown in a form

Samples

License

The MIT License

Copyright (c) 2015 Maksim Kozhukh

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

webix-firebase's People

Contributors

dandv avatar mafanya23 avatar mkozhukh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

webix-firebase's Issues

status?

Any news on this.

Ideally it would include making Webix 'reactive', something like how GluJs works with Extjs, a similar declarative javascript UI framework.

http://glujs.com/

That is, in order to work well with Firebase, Webix probably needs to support an MVVM pattern.

David

Clipboard paste do not save into Firebase DB

Using following datatable settings:

{
    select: 'cell',
    multiselect: true,
    editable: true,
    clipboard: 'repeat',
    editaction: 'dblclick',
}

The value is placed into the call but not saved into the Firebase so it disappears after browser reload.

Firebase exception

I am using webix form in window to update a record in firebase.

I am also using a datatable to display all records in a collection. When a update happens the following exception occurs:

FIREBASE WARNING: Exception was thrown by user callback. webix.DataStore.prototype.getItem@https://cdn.webix.com/edge/webix.js:375:23
webix.DataStore.prototype.updateItem@https://cdn.webix.com/edge/webix.js:375:75
webix.DataStore.prototype.Ef/<@https://cdn.webix.com/edge/webix.js:392:174
webix.proxy.firebase.load/</<@http://www.caliopa.com/libs/webix-firebase-master/codebase/webix-firebase.js:46:5
webix.DataProcessor<.ignore@https://cdn.webix.com/edge/webix.js:1129:49
webix.proxy.firebase.load/<@http://www.caliopa.com/libs/webix-firebase-master/codebase/webix-firebase.js:45:4
g.Vb/<@https://cdn.firebase.com/js/client/2.3.1/firebase.js:48:373
Db@https://cdn.firebase.com/js/client/2.3.1/firebase.js:43:165
zb@https://cdn.firebase.com/js/client/2.3.1/firebase.js:22:216
Ab@https://cdn.firebase.com/js/client/2.3.1/firebase.js:21:1260
g.update@https://cdn.firebase.com/js/client/2.3.1/firebase.js:210:471
U.prototype.update@https://cdn.firebase.com/js/client/2.3.1/firebase.js:251:431
formWindow.head.cols<.click@http://www.caliopa.com/controllers/panogeController.js:133:12
@https://cdn.webix.com/edge/webix.js:271:69
webix.EventSystem.callEvent@https://cdn.webix.com/edge/webix.js:21:331
@https://cdn.webix.com/edge/webix.js:38:294

In a button click handler i have a following code:
var sifrant = { title:"test" }

ref.update(sifrant, function(error){
if (error) {
webix.message("error message");
}
else {
webix.message("succes message");
}
});

There is no error triggered in the callback.

Double Data Loading

Data is loading twice into my table from Firebase. It looks like rows are being added from both the ref.once("value") and ref.on("child_added"). I'm guessing this is happening because I loaded the firebase ref at an earlier point in my app, so the functions were probably getting called synchronously.

I was able to fix the problem by wrapping the webix.ajax.$callback in a setTimeout

            setTimeout(function(){
                webix.ajax.$callback(view, callback, "", result, -1);
            }, 1)

Using proxy in angular apps

Hi,

I am using this proxy in angularJs application controller.

The problem is everytime i use it i get to much recursion error.

Is there any way to bypass this ?

Kanban sample doesn't save back to firebase

Cannot get this example working:
webix-firebase/samples/05_kanban.html

The proxy.save() method is never executed. What needs to be done, to get it saving the drag and drop events back to firebase? With a datatable instead it saves back. But not with the kanban widget. Has the Kanban widget a bug? Or do I need to implement the drag and drop events myself?

Having this:

  ...
  save: proxy
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.