Giter Site home page Giter Site logo

hoodie-plugin-angularjs's Issues

Having problems with adding new data to store

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

hoodiePromiseFnWrap Broken

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);
    }
}

Don't dirty the global scope

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?

Publish to Bower

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

Use ng-min to reduce code noise.
I could do that, if you want.

License

Please add License information to the repository, so we can start using it.

Adding to hoodieArray not populating couchdb

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>

getting back updated records

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.

Ghost items

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

Callback after successful bind

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.

Username should be cleared on signout

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.

Tag 0.1.1 release

That way I can do:

bower install https://github.com/elmarburke/hoodie-plugin-angularjs.git#0.1.1 --save

wrapping in Q defers/promises

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

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.