elmarburke / hoodie-plugin-angularjs Goto Github PK
View Code? Open in Web Editor NEWHome Page: https://npmjs.org/package/hoodie-plugin-angularjs
License: MIT License
Home Page: https://npmjs.org/package/hoodie-plugin-angularjs
License: MIT License
Before:
// Init Hoodie
var hoodie = new Hoodie()
window.hoodie = hoodie;
// Init Angular
angular.module('worldDominationApp', ['hoodie'])
After:
// Init Angular
angular.module('worldDominationApp', ['hoodie'])
We could check if window.hoodie is defined.
If this in undefined, create a new instance.
https://github.com/elmarburke/hoodie-plugin-angularjs/blob/master/src/hoodieProvider.js#L12
Would make the usage easier.
There should be a way to wrap the front end part of hoodie plugins (What is a hoodie plugin?) with $q promises.
Maybe we should wrap $q.when(β¦)
with an api in angular.module().config()
.
We must use the dynamic version of https://github.com/hoodiehq/hoodie.js as described in #32 by @svnlto.
Hi @elmarburke , great great work. π
I'm having some problems with adding new data to hoodie store, I'm getting the following errors:
GET http://127.0.0.1:6004/_api/user%2Ffc9ofwf/_changes?include_docs=true&since=0 401 (Unauthorized)
jquery.js:8625 n.ajaxTransport.k.cors.a.crossDomain.send
jquery.js:8161 n.extend.ajaxhoodie.min.js:6 ohoodie.min.js:7 h.request
hoodie.min.js:7 h.pullhoodie.min.js:7 h.bootstrap
hoodie.min.js:7 h.connecthoodie.min.js:6 d.connecthoodie.min.js:6 f
hoodie.min.js:6 djquery.js:3251 (anonymous function)
jquery.js:3094 n.Callbacks.j
jquery.js:3140 n.Callbacks.k.addjquery.js:3250 (anonymous function)
jquery.js:374 n.extend.each
jquery.js:3247 (anonymous function)
jquery.js:3307 n.extend.Deferred
jquery.js:3246 n.extend.Deferred.d.then
hoodie.min.js:6 (anonymous function)
jquery.js:3251 (anonymous function)
jquery.js:3094 n.Callbacks.jjquery.js:3206 n.Callbacks.k.fireWith
jquery.js:3258 (anonymous function)
jquery.js:3094 n.Callbacks.j
jquery.js:3206 n.Callbacks.k.fireWith
jquery.js:8259 xjquery.js:8600 n.ajaxTransport.k.cors.a.crossDomain.send.b
GET http://127.0.0.1:6004/_api/_users/org.couchdb.user%3Auser%2Ftest 404 (Not Found)
I looks like it is related to CORS (crossDomain), I'm using the default hoodie Provider:
hoodieProvider.url('/');
in the agnular module config.
Please help solving this issue.
Thanks,
Idanb11
Doing: hoodieAccount.on('authenticated', function() { ... });
Throws: TypeError: Cannot read property 'then' of undefined
This calls hoodiePromiseFnWrap
:
context[fnName].apply(context, args).then(angularDigestFn($rootScope, deferred.resolve), angularDigestFn($rootScope, deferred.reject));
This line expects context[fnName]
to return a promise, but it doesn't.
Using Hoodie 0.8.2
This is the source of the method called (in hoodie.js):
function bind(ev, callback) {
var evs, name, _i, _len;
evs = ev.split(' ');
for (_i = 0, _len = evs.length; _i < _len; _i++) {
name = namespace + evs[_i];
hoodie.eventsCallbacks[name] = hoodie.eventsCallbacks[name] || [];
hoodie.eventsCallbacks[name].push(callback);
}
}
Many places defining variables on the global scope.
We should clear that.
var hoodieModule
//...
function hoodieEventWrap(hoodieInstance, eventName, $rootScope, fn) {
//...
function hoodiePromiseFnWrap(context, fnName, $q, $rootScope) {
//...
function angularDigestFn($rootScope, callback) {
//...
var HOODIE_URL_ERROR =
I've started this locally, should I send you a PR?
The most current version of this plugin does not include an admin dashboard implementation, which results in some ugly default output. Until hoodie detects a missing admin dashboard component, I suggest a simplistic approach as illustrated here: https://github.com/appback/hoodie-plugin-git/tree/master/admin-dashboard
I know you can install this via hoodie cli, but as it's frontend only, why shouldn't one be able to install it via bower (just like hoodie itself).
Use ng-min to reduce code noise.
I could do that, if you want.
$scope.save = function() {
$scope.tasks.push($scope.taskToModify);
$state.go('index');
};
will not sync $scope.tasks
to Hoodie, as $scope.$watch()
listener has no opportunity to be called.
I do have a workaround but not so obvious:
<button ng-click="save()" ui-sref="index">
As the scope object bound is always an Array, is it possible to override Array methods? Or are there other alternatives?
Please add License information to the repository, so we can start using it.
I would just like to say that your plugin is awesome!
If you run the following code and then look in couchdb, you'll see that the new item hasn't been added. If you use hoodie.store.add() directly then it appears to work, but I think there is a problem with adding new items via your plugin. (Your plugin appears to update items fine). I briefly tried to debug this, but haven't found the problem yet and was hoping that someone may have some insight. I think it may have something to do with the item being stored in local storage and then flagged improperly so that hoodie doesn't send the new data to couchdb.
<!DOCTYPE html>
<html ng-app="todos">
<head>
<meta charset="utf-8">
<title>Todos</title>
</head>
<body>
<h2>Todos</h2>
<div ng-controller="TodoCtrl">
<ul ng-model="todos">
<li ng-repeat="todo in todos">
<span>{{todo.txt}}</span>
</li>
</ul>
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.4/angular.min.js"></script>
<script src="/_api/_files/hoodie.js"></script>
<script>
var hoodie = new Hoodie();
window.hoodie = hoodie;
hoodie.account.signUp('[email protected]', 'secret');
hoodie.account.signIn('[email protected]', 'secret');
angular.module('todos', ['hoodie'])
.config(function(hoodieProvider) {
hoodieProvider.url('http://127.0.0.1:6001');
})
.controller('TodoCtrl', function ($scope, hoodieArray) {
hoodieArray.bind($scope, 'todos', 'todo');
$scope.todos.push({txt: 'take out trash'});
$scope.todos.push({txt: 'clean dishes'});
});
</script>
</body>
</html>
Do you have snippet example of using Dependency Injection for hoodieStore?
thanks and sorry if it is a little bit basic :)
I am trying to display / edit some CouchDB documents and using Hoodie and angular in in the process.
Documents display just fine. I can also edit documents. But I can only do that once.
The problem I seem to have is that hoodie-plugin-angularjs will write my edited document back to Hoodie but the document is not updated in the array I have in my model. As a consequence it will not have the latest _rev and the second edit will fail.
I canβt really figure out at this stage whether Iβm doing something in a wrong way here or whether this is an issue with hoodie-plugin-angularjs.
A simple example is given by this controller which objects of type test
to the items
variable in its scope. It also provides a function to edit a field in the document.
testApp.controller('items', ['$scope', 'hoodieArray', function ($scope, hoodieArray) {
$scope.personen = [];
hoodieArray.bind($scope, 'items', 'test');
$scope.updateItem = function (theItem) {
if (theItem.count === undefined) {
theItem.count = 0;
}
theItem.count++;
};
}]);
using it with this angular template
<ul class="list-group" ng-controller="items">
<li ng-repeat="item in items track by item.id"
class="list-group-item">
<a ng-click="updateItem(item)" href="">
{{item.id}}
({{item.count}})
{{item._rev}}
</a>
</li>
</ul>
β¦ I would expect to get a list of clickable items displaying the id / count / _rev of each document. Clicking a document will edit it by incrementing the count. This change will be stored by hoodie, creating a new _rev value in the process and that change will be reflected in the list.
The behaviour I am seeing, however, is that the count does increase but the _rev field does not. Hence my suspicion that something unexpected is going on.
Hi,
I've got a weird problem. First the code:
var app = angular.module("app", ['hoodie']).config(function(hoodieProvider) {
hoodieProvider.url('http://localhost:6004/');
});
app.controller("ctrl", function($scope, $http, hoodieArray) {
$scope.libTable = [];
$scope.add = function(item) {
$scope.libTable.push(item);
};
hoodieArray.bind($scope, 'libTable', 'table');
});
When adding an item and refreshing the site, ghost items are created. They are not in the hoodie DB, but in the libTable array. Each time I refresh the site, I get 4 new items and I have no idea, why.
I am logged in (but used default hoodie-lib to sign in, could that be a problem?). The other thing I can think of would be the local storage of hoodie on the client side. But why are new items are created? Even if I remove the push() call items get created.
Hope you can help me. Thanks in advance,
Michael
I'm trying to execute some code after hoodieArray.bind
successfully binds to $scope
. I'm considering something like:
service.bind = function ($scope, key, hoodieKey, afterBind) {
....
hoodieStore.findAll(hoodieKey).then(function (data) {
$scope[key] = data;
if (afterBind) afterBind(); \\ callback
});
Should I code up a PR? Is there a better way of handling this via promises?
My ultimate goal is to bind an edit view's $scope
to an element in the array and not just the entire array, but I believe this binding needs to take place after the full array has been bound.
Currently the code reads:
hoodie.account.on(eventName, function (username) {
$rootScope.$apply(function () {
service.username = username;
});
My understanding of Hoodie is that hoodie.account.username is defined if a user is logged in, but the signout event is called with the username of the signing-out user. So once you are signed in, there is no way to clear hoodieAccount.username. I'm guessing this code should check for the signout event and set hoodieAccount.username to null in that case.
I'm fairly new to Hoodie, so I may be wrong. I currently have an Angular app that, once I'm logged in, I can't log out of until I reload and get a fresh scope. Things react fine when I log in and username is assigned an initial value, but it never clears even when hoodie:signout fires.
That way I can do:
bower install https://github.com/elmarburke/hoodie-plugin-angularjs.git#0.1.1 --save
In order to expose services for hoodie plugins i.e. hoodie-global-share
(see here https://github.com/svnlto/hoodie-plugin-angularjs/commit/a13164433818415abd99a533bcc672d08800b4b9)
A compiled version of hoodie.js is required ( the one that is provided by hoodie-server ).
I'll be adding a PR that will set this up for the project so that when we run tests we have access to the above. Any thoughts, objections?
I think it would be really cool if we modified the plugin to use omnibinder (https://github.com/jeffbcross/omnibinder). Any thoughts? When I get some free time, I'll try to help out with this.
First of all, I love the idea to use a hoodie plugin to provide an angular service. We should do the same for all the JS MC* frameworks out there.
I wonder why you do this
this.findAll = function (search) {
var deferred = $q.defer();
hoodie.store.findAll(search)
.done(function (objects) {
deferred.resolve(objects);
});
return deferred.promise;
};
instead of doing this
this.findAll = hoodie.store.findAll
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.