Giter Site home page Giter Site logo

angularsails's People

Contributors

askmike avatar astromash avatar brandom avatar chrischares avatar dbkaplun avatar ddelrio1986 avatar devjones avatar ghernandez345 avatar kuirak avatar mikermcneil avatar proloser avatar robwormald avatar seth2810 avatar sgress454 avatar thebigredgeek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

angularsails's Issues

Subscription to backend events doesn't work after reload

I have built an app relying on the sails Blueprints API and the fact that:

autoSubscribe is normally set to true, which means that any time a socket request is made for a model, the requesting socket will be subscribed to all events for that model instance
stackoverflow

so i resolve the route data by making a request to sails in the route resolver and pass it (as a promise) to the route controller (which gets instantiated after the promise is resolved/rejected)... all good but $sailsSocket.subscribe('venue', …) in my controller doesn't do it's trick after i browser-reload the venue details page. (it does work after i visit other routes of my app, just not immediately after reload)

what am i missing?

angular
.module('cineApp', ['ngRoute', 'sails.io', 'eventAppControllers'])
.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {

    $locationProvider
        .html5Mode(true);

    $routeProvider
        .when('/venues/:slug', {
            templateUrl: '/templates/venue/single.html',
            controller: 'VenueDetailsController',
            resolve: {
                'venueData': function($sailsSocket, $q, $route) {

                    var deferred = $q.defer();

                    $sailsSocket
                        .get('/api/venue/'+$route.current.params['slug'])
                        .success(function(data, status, headers, config) {

                            deferred.resolve(data);

                        });

                    return deferred.promise;

                }
            }
        })
        .otherwise({
            templateUrl: '/templates/error404.html',
            controller: 'Error404Controller'
        });

}]);


angular.module('eventAppControllers', [])
.controller('VenueDetailsController', ['$scope', '$sailsSocket', '$route', '$location', 'venueData', function($scope, $sailsSocket, $route, $location, venueData) {

    $scope.venueData = venueData ? venueData : null;

    //  Subscribe to changes
    //——————————————————————————————
    $sailsSocket.subscribe('venue', function(res){

        if ( res.verb == 'updated' ) {

            if ( 'slug' in res.data )
                $location.path('/venues/'+ res.data.slug);

            $route.reload();

        }

        if ( res.verb == 'destroy' )
            $route.reload();

    });

}]);

Adjusment for unsubscribing

Just FYI, I've seen some issues here and on various other sites about removing event subscriptions with ngSails ($sailsSocket). I'm pretty sure that this has to do with Socket.IO changing some of their method names. For me, at least, making the simple change below gets this functionality working for me using socket.io-client 1.3.7, sails.io.js 0.11.5, and angularSails 0.12.1.

The following block (starting at line 1278 in ngsails.io.js):

    //TODO normalize http paths to event names
    connection.subscribe = function(event,handler){
        var callback = tick($window.io.socket,handler);
        $window.io.socket.on(event,callback);
        return angular.bind($window.io.socket, $window.io.socket.removeListener, event, callback);
    }

Should be updated to:

    //TODO normalize http paths to event names
    connection.subscribe = function(event,handler){
        var callback = tick($window.io.socket,handler);
        $window.io.socket.on(event,callback);
        return angular.bind($window.io.socket, $window.io.socket.off, event, callback);
    }

Then, unsubscribing will work correctly, i.e.:

// Subscribe
var fnUnsubscribe = $sailsSocket.subscribe('event', function(oEvent) { /* Function body */ });

// Unsubscribe
fnUnsubscribe();

Grunt / Build / Switch to gulp?

Angular 2.0 as far as I know is going to be using Gulp for build. I find the stream concept nicer as well, but I'm no expert on either of these tools. Discuss?

$sailsSocket() error on get method

Hello,

I'm trying to use $sailsSocket.get() with params.
I did :

var params = {
  doctor: doctor,
  start: start,
  end: end
}
$sailsSocket({method: 'GET', url: '/appointments', params: params})
  .success(...)
  .error(...)

But I got some weird errors on ngsails :

TypeError: v.toIsoString is not a function
    at ngsails.io.js:1198
    at Object.forEach (angular.js:323)
    at ngsails.io.js:1195
    at forEachSorted (ngsails.io.js:1538)
    at buildUrl (ngsails.io.js:1191)
    at sendReq (ngsails.io.js:1101)
    at $get.serverRequest (ngsails.io.js:851)
    at processQueue (angular.js:13189)
    at angular.js:13205
    at Scope.$get.Scope.$eval (angular.js:14401)

Am I doing something wrong ?

Thanks,
Gabriel

Support for Angular 2

ng2 is on beta stage atm, so I'm just wondering if there would be angularSails library for ng2 too.

Correct way injecting angularSails?

Hi,
If I'm using var myApp = angular.module('app ', ['sails.io']); and after that injecting $sailsSocket in service/controller/...
I have no .on method, but I just use .subscribe (same thing).
If I'm var myApp = angular.module('app ', ['angularSails.io']); and after that injecting $sailsSocket
$sailsSocket is just plain function.
and after I do for example var socket = $sailsSocket(); I can use .on method but not .subscribe.
Looks like 'sails.io' is the way to go as it injects proper object, but why such a different behavior?

p.s. I had difficult time making angularSails to work. as file name is 'ngsails.js', inject you should 'sails.io' and documentation says only about methods you can use.

.subscribe fired multiple times

Hello everyone, I'm currently encountering issues with .subscribe fired multiple times. If I set some state (ngRoute or ui-router) including some view '

' using .subscribe() method inside someCtrl.js => I'm gonna get the events multiples times.

Is there a way to avoid .subscribe to be fired more than once?

Regards

Cannot get to work with yo angular

I initialized my app with yo angular --coffee, then installed angularSails with bower install.
After 'grunt serve', open up localhost:9000, I got this error:
image

$sailsSocket.get is not a function

I'm getting this error for anything related to the $sailsSocket eg .on, .subscribe. I've included in my main module angularSails.io and $sailsSocket in my controller.

I'm using the latest version 0.12.1. Do I need to include sails.io too?

Missing a ) in dist/ngsails.io.js

Hi,
since you change 'module.prefix' in v0.11.4 Mozilla console report an error ''Missing a )" in dist/ngsails.io.js when injected. No problem with src directory, so i think it's a build problem, not a code problem. The content of 'module.suffix' should be something like:

}));

Undefined

Just founded some errors with this library:

  1. statusCode undefined
TypeError: Cannot read property 'statusCode' of undefined
    at socketResponse (http://wunder.sytes.net:1338/vendor/angularSails/dist/ngsails.js:836:25)
    at wrappedCallback (http://wunder.sytes.net:1338/bower_components/angular/angular.js:11319:81)
    at http://wunder.sytes.net:1338/bower_components/angular/angular.js:11405:26
    at Scope.$eval (http://wunder.sytes.net:1338/bower_components/angular/angular.js:12412:28)
    at Scope.$digest (http://wunder.sytes.net:1338/bower_components/angular/angular.js:12224:31)
    at http://wunder.sytes.net:1338/bower_components/angular/angular.js:12450:26
    at completeOutstandingRequest (http://wunder.sytes.net:1338/bower_components/angular/angular.js:4300:10)
    at http://wunder.sytes.net:1338/bower_components/angular/angular.js:4601:7 
  1. Weird response handling
    I have following code in use
$sailsSocket
    .get("/user/" + $rootScope.currentUser.id)
    .success(function(data) {
        console.log("success");
        return data;
    })
    .error(function(data, a, b, c) {
        console.log("error");
        return data;
    });

And that will not ever hit the .success(), this will always hit to .error() for some reason. Sails log shows me something like:

verbose: Routing message over socket:  { method: 'get', data: {}, url: '/user/1', headers: {} }
verbose: sending data ack packet
verbose: websocket writing 6:::4+[{"body":{ .... }, },"statusCode":200}]

How the heck do you start and view the demo?

I cd into the example folder, and run sails lift and everything appears to start... but I can't figure out what port the app is running on...

Seems simple enough but for a demo this should be made 100 percent obvious... readme maybe?

JSDocs

Any thoughts about automating documentation using JSDocs/NGDocs and then hosting said docs on github pages?

No way to unsubscribe

I'm not sure why subscribe sends a promise (I guess to show the status of the subscribe ping to the backend?). It may make more sense to return an unsubscriber function or something. I have no idea how to unsubscribe at this point. Alternatively, if the promise response is absolutely necessary, create an unsubscribe method on the sailssocket that i can give it something... Iunno.

server error 500 req.isAuthenticated is not a function

Hello, I'm using passport to do authorization, i'm getting below error while using $sailsSocket

is there anyway to authorize $sailsSocket requests?

thanks!

Error from console:

error: Sending 500 ("Server Error") response:
 TypeError: req.isAuthenticated is not a function
    at module.exports (\api\policies\sessionAuth.js:1
4:11)
    at routeTargetFnWrapper (\node_modules\sails\lib\
router\bind.js:179:5)
    at \node_modules\sails\lib\router\bind.js:244:14
    at callbacks (\node_modules\sails\node_modules\ex
press\lib\router\index.js:164:37)
    at param (\node_modules\sails\node_modules\expres
s\lib\router\index.js:138:11)
    at param (\node_modules\sails\node_modules\expres
s\lib\router\index.js:135:11)
    at pass (\node_modules\sails\node_modules\express
\lib\router\index.js:145:5)
    at nextRoute (\node_modules\sails\node_modules\ex
press\lib\router\index.js:100:7)
    at callbacks (\node_modules\sails\node_modules\ex
press\lib\router\index.js:167:11)
    at \node_modules\sails\lib\router\bind.js:187:7
    at module.exports (\node_modules\sails\lib\hooks\
cors\clear-headers.js:14:3)
    at routeTargetFnWrapper (\node_modules\sails\lib\
router\bind.js:179:5)
    at callbacks (\node_modules\sails\node_modules\ex
press\lib\router\index.js:164:37)
    at param (\node_modules\sails\node_modules\expres
s\lib\router\index.js:138:11)
    at pass (\node_modules\sails\node_modules\express
\lib\router\index.js:145:5)
    at nextRoute (\node_modules\sails\node_modules\ex
press\lib\router\index.js:100:7) [TypeError: req.isAuthenticated is not a functi
on]

policies\sessionAuth.js

module.exports = function(req, res, next) {

  // User is allowed, proceed to the next policy,
  // or if this is the last policy, the controller
  if (req.isAuthenticated()) {
    return next();
  }

  // User is not allowed
  // (default res.forbidden() behavior can be overridden in `config/403.js`)
  //return res.forbidden('You are not permitted to perform this action.');
  return res.redirect('/auth/signin/');
};

config\policies.js

module.exports.policies = {

  /***************************************************************************
  *                                                                          *
  * Default policy for all controllers and actions (`true` allows public     *
  * access)                                                                  *
  *                                                                          *
  ***************************************************************************/

  '*': 'sessionAuth',

  'auth': {
    '*': true
  }

  /***************************************************************************
  *                                                                          *
  * Here's an example of mapping some policies to run before a controller    *
  * and its actions                                                          *
  *                                                                          *
  ***************************************************************************/
    // RabbitController: {

        // Apply the `false` policy as the default for all of RabbitController's actions
        // (`false` prevents all access, which ensures that nothing bad happens to our rabbits)
        // '*': false,

        // For the action `nurture`, apply the 'isRabbitMother' policy
        // (this overrides `false` above)
        // nurture  : 'isRabbitMother',

        // Apply the `isNiceToAnimals` AND `hasRabbitFood` policies
        // before letting any users feed our rabbits
        // feed : ['isNiceToAnimals', 'hasRabbitFood']
    // }
};

Search values in query

I noticed that _getInitalData doesn't pass possible query parameters to sailsSocket.get() is there are purpose for this or it's just not yet implemented?

Basically I would like to fetch only specified models like:

$scope.foo = $sails("/foo", {name: "bar"});

Or is there another way to do this?

Ionic App Using Angular-Sails: No 'Access-Control-Allow-Origin' header is present

Hi @irlnathan Good talking to you and team a couple weeks back. Still doing my eval and running into a bit of a snag. Thanks for your help!
Scott

Where am I going wrong here?

SailsJS API: http://localhost:5000
Ionic Mobile App: http://localhost:8100

Error:
XMLHttpRequest cannot load http://localhost:5000/socket.io/?EIO=3&transport=polling&t=1413658242581-1. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8100' is therefore not allowed access.

app.js From Ionic App Using Angular-Sails
.config(['$sailsProvider', function ($sailsProvider) {
$sailsProvider.url = 'http://localhost:5000';
}]);

cors.JS From SailsJS

module.exports.cors = {

/***************************************************************************

  •                                                                      *
    
  • Allow CORS on all routes by default? If not, you must enable CORS on a *

  • per-route basis by either adding a "cors" configuration object to the *

  • route config, or setting "cors:true" in the route config to use the *

  • default settings below. *

  •                                                                      *
    

    ***************************************************************************/

    allRoutes: true,

    /***************************************************************************

  •                                                                      *
    
  • Which domains which are allowed CORS access? This can be a *

  • comma-delimited list of hosts (beginning with http:// or https://) or *

  • "*" to allow all domains CORS access. *

  •                                                                      *
    

    ***************************************************************************/

    origin: '*',

    /***************************************************************************

  •                                                                      *
    
  • Allow cookies to be shared for CORS requests? *

  •                                                                      *
    

    ***************************************************************************/

    // credentials: true,

    /***************************************************************************

  •                                                                      *
    
  • Which methods should be allowed for CORS requests? This is only used in *

  • response to preflight requests (see article linked above for more info) *

  •                                                                      *
    

    ***************************************************************************/

    methods: 'GET, POST, PUT, DELETE, OPTIONS, HEAD',

    /***************************************************************************

  •                                                                      *
    
  • Which headers should be allowed for CORS requests? This is only used in *

  • response to preflight requests. *

  •                                                                      *
    

    ***************************************************************************/

    headers: 'content-type, access-control-allow-origin, authorization'

};

Model/Controller "bundle" process from server-side.

Chatted w/ @thebigredgeek on IRC the other night about this, making a note to get input.

One of the core concepts behind this effort for me is being able to re-use the logic / information from the Sails server. Ideally, I'd like to be able to (optionally) package a config type file (likely as an Angular constant) that would contain:

  • model definitions - attributes, relations, validations, etc.
  • routes
  • (eventually) cool stuff like permissions/policies/etc.

This can then be injected into your application, and used to automatically configure your (angular) Models.

Two schools of thought here - loading this information from the server at runtime, or as part of the client side code. The latter is preferable for me, as the majority of my Angular code needs to be able to run without relying on the Sails server to be reachable.

I've poked around a couple of ways of doing this - they're all a bit dirty so far. Best option might be to plug it into the sails www build process.

Discuss?

Initialize sails socket manually

Hi, I'm currently using ngSails + sails.io library and I'm initializing the connection using io.sails.url = 'http://localhost:1337' (Since the autoConnect is set to true by default).
However, I have a auth/login page and I would like to initialize the socket once the user is logged in (in my Angular application).
I tried to set autoConnect to false, and manually do a io.connect() once the user is logged in. However, the $sailsSocket is not recognized anymore using my method.
Any suggestion on how I can manually init the socket and still use the $sailsSocket adapter?
Best regards,

Interceptors not applying headers

I'm having a problem applying the following interceptor to sailsSocket.

Given the following in my config block:

$sailsSocketProvider.interceptors.push(function($q){
    return {
        request: function(config){
            $sailsSocketProvider.defaults.headers.foo = "bar";
            return config;
        }
    }
});

The interceptor is firing, I can see from chrome inspector that the interceptors are not being applied to the outgoing requests.

bower.json main wrong

The main attribute in bower.json links to the non existent /dist/angularSails.min.js you should change it to ./dist/ngsails.js

Update is not working in example

in "example/assets/js/app.js"

$scope.updateUser = function () {
$scope.user.$update();
}

is not working as expected. Not throwing any error, silently fails.

Is it still under development or some issue.

Setting header config not working

Not able so set the Auth header when my user logs in and has a valid auth token based on the documentation

$sails.defaults.headers.common.Authorization = 'Basic '+idToken;

.controller('LoginCtrl', function($scope, auth, $state, store, $sails) {
auth.signin({
//some code here
}, function(profile, idToken, accessToken, state, refreshToken) {
//some code here

//Make sure that the socket server has Authorization Header Set
$sails.defaults.headers.common.Authorization = 'Basic '+idToken;

$state.go('home');

}, function(error) {
console.log("There was an error logging in", error);
});
})

Incompatibility with stable (0.10.5) version of sails?

angularSails is using the latest version of sails.io.js, which is currently 0.11.4. From my testing it seems this version may not be backwards compatible with the stable version of the sails (v 0.10.5).

I get CORS error from socket.io when using v0.11.4 sails.io.js with v0.10.5 sails server. This despite the fact I've allowed all CORS options.

I had to force angularSails to use v0.10.3 of sails.io.js to get everything working since I'm on v0.10.5 of the sails server.

See commit here:
devjones@5563226

BLOCKER: TypeError: Cannot read property 'connected' of undefined

TypeError: Cannot read property 'connected' of undefined
    at angular.module.constant.constant.factory.factory.provider.SailsSocket.isConnected (ngsails.io.js:292)
    at angular.module.constant.constant.factory.factory.provider.SailsSocket._request (ngsails.io.js:376)
    at angular.module.constant.constant.factory.factory.provider.SailsSocket.get (ngsails.io.js:299)

$sailsSocket .get is not a function

Hi guys I have included ngSails.js into my project, as well I have added angularSails.io to my app, but when I try to

$sailsSocket.get('/')
    .success(function(data) {
});

I get

.get is not a function I'm unsure what I'm doing wrong here any help would be great thanks.

    <script src="/js/dependencies/sails.io.js"></script>
    <script src="/js/dependencies/angular.js"></script>
    <script src="/js/dependencies/angular-route.js"></script>
    <script src="/js/dependencies/ngsails.io.js"></script>

this is how it is being included, version of Angular are 1.3.16

app.controller('CreateUserController', ['$scope', '$http', '$sailsSocket', function($scope, $http, $sailsSocket)

Query params not functioning properly with sailsSocket request

The following code doesn't obey the query params. It pulls all rows from the model.

var query = { where: [{ checkIn: { '>': '2016-05-24T00:00:00.000Z' } }] }; $sailsSocket.get("/visit", {params:query}) .then(function(res) { $scope.visitReportResults = res.data; })

Changing $sailsSocket to $http resolves the issue. According to Rob, it's an issue with the buildParams code.

$sailsSocket.on() function is 'undefined'

I'm in the process of switching our code from using angular-sails to using your angularSails, however, it seems that there are some issues.

  1. in your repo, you have an examples folder with both a www and an assets folder. These two seem to be using different approaches to including the angularSails (www seems to be using something completely different). So it is not clear which is the advised way.
  2. [the main issue I am writing for] when adding the 'sails.io' dependency into my module declaration, and injecting '$sailsSocket' into my controller, it is saying that 'on' ($sailsSocket.on()) is undefined. Looking at the dist/ngsails.io.js file, line 587 has 'createShortMethods' for 'get','delete','head' and then line 634 has the 'createShortMethodsWithData' function for 'post','put'. The comment block starting on line 617 mentions the on method, but it doesn't seem to be included in either of these two function calls.
  3. a detailed example on the JSDocs would be great for the preferred implementation of this.

Any help that you guys can provide would be a great help!!

Complex where conditions are being lost

I found that this fails:

$sailsSocket.get('/someurl', {
  params: { where: { "recipient": { "$exists": false } }
});
// becomes: query: { where: '{"recipient":{}}' }

but this works:

$sailsSocket.get('/someurl', {
  params: { where: { or: [ { id1: id1, id2: id2 }, { id1: id2, id2: id1 } ] }
});

To fix this I've had to JSON.stringify() the where object manually.

change in bower.json to report support for angular 1.4

The current bower.json file says that the code needs angular 1.2. I am trying to use 1.3 and have to have a bower install work without errors/warnings. Since you have fixed this to work with 1.4, can I ask that the bower file be updated to reflect this relaxed dependency?

Adapt for .10+ client SDK usage

@mikermcneil could you point me in the direction of / go over with me what you're changing over in the main repo re the client SDK stuff? Dont want to track too far off what you're doing for vanilla sails.io.js usage.

Karma testing with AngularSails

I see some mention in the documentation about $sailsMockBackend used when testing and that it can be trained with responses, but I don't see anything about how to manage this? Can someone point me in the right direction?

weird handling with $sailsSocket.post()

I noticed that $sailsSocket.post() will not hit the .error(). I have following code in my controller (note just a demo for usage).

HeaderController.js:

$sailsSocket
    .post("/Sprint", {foo: "bar", bar: "foo")
    .success(function(data){
        console.log("success");
        console.log(data);
        console.log(foo);
    })
    .error(function(data) {
        console.log("error");
        console.log(data);
        console.log(foo);
    });

And in browser console i get following.

success HeaderController.js:203
Object {error: "E_VALIDATION", model: "Sprint", summary: "1 attribute is invalid", status: 400, invalidAttributes: Object}
error: "E_VALIDATION"
invalidAttributes: Object
title: Array[2]
__proto__: Object
model: "Sprint"
status: 400
summary: "1 attribute is invalid"
__proto__: Object

Don't know if this is real sails problem or this library but this is confusing atm.

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.