Giter Club home page Giter Club logo

angular-odata-es5's Introduction

Angular OData Library (es5)

Greenkeeper badge Build Status codecov npm version

Demo

https://StefH.github.io/angular-odata-es5/demo/

Table of contents

About

The goal is to create a fluent API for querying, creating, updating and deleting OData resources in Angular > 2. Note that this library targets 'es5' so that Uglify will work correctly.

Installation

Install through npm:

npm install --save angular-odata-es5

Usage

import { ODataConfiguration, ODataServiceFactory, ODataService } from "angular-odata-es5";
import { bootstrap } from "@angular/platform/browser";
    
@Injectable()
class MyODataConfig extends ODataConfiguration{
    baseUrl="http://localhost:54872/odata/";
}

bootstrap(app, [
    provide(ODataConfiguration, { useClass:MyODataConfig }),
    ODataServiceFactory,
]

//An example model interface
interface INotification {
    Id: number;
    CommentId: number;
    Comment: IComment;
    FromId: number;
    From: IResource;
    Priority: number;
    SendDate: Date;
    IsArchived: boolean;
    Text: string;
}

//An example component
@Component({
  ...
})
export class NotyListComponent {
    private odata: ODataService<INotification>;
    constructor(private odataFactory: ODataServiceFactory, ...) {
        this.odata = this.odataFactory.CreateService<INotification>("notification");
    }
    
    getOneNoty(id: number) {
        this.odata.Get(id).Select("Id,Text").Expand("From,To").Exec()
        .subscribe(
            singleNoty => {...},
            error => {...}
        );
    }

    getNotys(){
        this.odata
            .Query()                    //Creates a query object
            .Top(this.top)
            .Skip(this.skip)
            .Expand('Comment, From')
            .OrderBy('SendDate desc')
            .Filter(this.filterString)
            .Exec()                     //Fires the request
            .subscribe(                 //Subscribes to Observable<Array<T>>
            notys => {
                this.notys = notys;     //Do something with the result
            },
            error => {
                ...                     //Local error handler
            });
    
    }
}

You may also find it useful to view the demo source.

Usage without a module bundler

<script src="node_modules/angular-odata-es5/bundles/angular-odata-es5.umd.js"></script>
<script>
    // everything is exported AngularODataES5 namespace
</script>

Documentation

All documentation is auto-generated from the source via compodoc and can be viewed here: https://StefH.github.io/angular-odata-es5/docs/

Development

Prepare your environment

  • Install Node.js and NPM (should come with)
  • Install local dev dependencies: npm install while current directory is this repo

Development server

Run npm start to start a development server on port 8000 with auto reload + tests.

Testing

Run npm test to run tests once or npm run test:watch to continually run tests.

angular-odata-es5's People

Contributors

axeltaylor avatar bastienlemaitre avatar dependabot[bot] avatar diegomvh avatar ernie-suplari avatar geerzo avatar greenkeeper[bot] avatar kamil-zacek avatar kg3rk3n avatar markwaddle avatar matracey avatar pleshakovalexander avatar shvydky avatar sir-j avatar snyk-bot avatar stefh 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

angular-odata-es5's Issues

Post with odata.bind? Documentation missing, at least

How is one supposed to make a post that references another object in a navigation property?

Example:

 export interface Module {
    Identity: Edm.Guid;
    Equipment?: PropertyCore.Equipment;
}

I need to post with a reference to an existing Equipment (and yes, that makes little sense - I removed all the other elements).

Our front end is stuck here and I fail to find any documentation at all. Adding an equipment (wich only the Identity set, which is the key) results in a deep insert style of post (i.e. Equipment = { sub elements }, while in reality we want a reference to an existing object:

{"@odata.type":"#PropertyCore.Module","[email protected]":"http://localhost/Equipment(000a129f-a55c-441f-9d7a-d95d53986aa4)"}

Is there any way to do this?

An in-range update of rxjs is breaking the build 🚨

Version 5.3.2 of rxjs just got published.

Branch Build failing 🚨
Dependency rxjs
Current Version 5.3.1
Type dependency

This version is covered by your current version range and after updating it in your project the build failed.

rxjs is a direct dependency of this project this is very likely breaking your project right now. If other packages depend on you it’s very likely also breaking them.
I recommend you give this issue a very high priority. I’m sure you can resolve this πŸ’ͺ

Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

unable to set the baseUrl

I am unable to set the baseurl from the class extends from ODataConfiguration. I am using it in angular4.Please some can help me thank you

Question: POST Example

There is no POST example given in documentation, Can you please provide one post sample through this component from angular

Issue: Upgrade to Angular 6

I'm attempting to upgrade to Angular 6 and this is the only package I have that hasn't upgraded. I'm using rxjs-compat currently, but wouldn't mind removing it if I can get this upgraded :)

Setting Post Headers

Trying to set post headers.

config.baseUrl = this.DataServiceURL;
config.postRequestOptions.headers = new HttpHeaders({
  'Accept': 'application/json',
  'Content-Type': 'application/json; charset=utf-8',
  'Session': ''});

Never seems to set the headers.

Am i missing something?

Programmatically change arrays of OrderBy or Filter of ODataQuery

Hi @StefH,

Sorry to bother you again but do you think there could be a way to change programmatically the OrderBy or Filter.

I explain myself :

I use angular-odata-es5 and PrimeNG-DataTable-Extensions and after executing applyLazyLoadEvent I would like to modify the sorting depending on different cases.

If I do query.OrderBy or query.Filter it replaces the existing ones and there is no way to get what were the already existing values.

The problem is that these values are in private and there is no way to get them :

  • private _filter: string[] = [];
  • private _orderBy: string[] = [];

If there would be two functions returning these two arrays (a sort of GetOrderBy and GetFilter), then I could do anything I want on the arrays and do again OrderBy or Filter.

Thanks in advance !

An in-range update of @angular/animations is breaking the build 🚨

Version 4.2.2 of @angular/animations just got published.

Branch Build failing 🚨
Dependency @angular/animations
Current Version 4.2.1
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As @angular/animations is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ

Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

feature request: expose URL to be used by other sources

Hi there,

Great library!

It would be handy if the URL that is used could be accessed anywhere in the pipeline.

i.e. instead of Exec() a user could invoke Url() or Uri() and get the built URL up to that point. This would allow this great library to be used when there are maybe other kinds of odata sources (i.e. DevExtreme's grid data source)

Allow option to $expand on PUT/POST/PATCH

OData allows the ability to do something like a POST with an $expand which then returns an object with an expanded property, e.g.:

Request

POST http://localhost/SomeService/v1/SomeResource?$expand=NestedObjects
Accept: application/json
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9

{
  "Name": "Dummy Object",
  "NestedObjects": [
    {
      "Name": "Dummy Nested Object"
    }
  ]
}

Response

HTTP/1.1 200 OK
Content-Type: application/json; odata.metadata=minimal
Location: http://localhost/SomeService/v1/SomeResource?$expand=NestedObjects
OData-Version: 4.0

{
  "@odata.context": "http://localhost/SomeService/v1/$metadata#SomeResource/$entity",
  "Id": 1234,
  "Name": "Dummy Object",
  "NestedObjects": [
    {
      "Id": 4321,
      "Name": "Dummy Nested Object"
    }
  ]
}

In a specific use case that I'm using, we PUT an object with a nested object to update both the parent and the children in the database. When we get a response, it'll just return the top level object by default unless we include the $expand operator

OrderBy on nested properties broken

Hi @StefH !

I don't know when but I think there is an update where you modified your code and it seems that the OrderBy on nested properties doesn't work anymore...
(Perhaps other operations with nested properties are also broken, I didn't try...)

It creates an url which looks like something like ...$orderby=Boss.Name instead of ...$orderby=Boss/Name which is the good syntax...

Thanks in advance !

PS : By the way, would it be possible to update PrimeNG-DataTable-Extensions to be compatible with the most recent version of angular-odata-es5 ?

An in-range update of ts-node is breaking the build 🚨

Version 3.0.5 of ts-node just got published.

Branch Build failing 🚨
Dependency ts-node
Current Version 3.0.4
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As ts-node is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ

Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build failed Details

Commits

The new version differs by 7 commits.

  • c18331a 3.0.5
  • 5cf97b1 Add --inspect-brk to known flags (#343)
  • 7dfb3e3 Pin node tests at 6.x (#340)
  • 633d537 chore(package): update chai to version 4.0.1 (#337)
  • b751a56 Define exports and improve getTypeInfo help (#332)
  • d018300 Update yn default option
  • cc3bf22 Expose _ bin file for consumers to use

See the full diff

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

An in-range update of tslint is breaking the build 🚨

Version 5.3.0 of tslint just got published.

Branch Build failing 🚨
Dependency tslint
Current Version 5.2.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As tslint is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ

Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

Release Notes v5.3.0

This change may require a change to tslint.json

πŸŽ‰ Notable features & enhancements

Thanks to our contributors!

  • Andy Hanson
  • Klaus Meinhardt
  • Martin Probst
  • Filipe Silva
  • walkerburgin
  • RenΓ© Scheibe
Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

string function params containing numbers are not quoted

The parameter processing code assumes that strings that can be parsed to numbers should be sent as numeric parameters, ie. without quotes. This seems like a bad assumption, and prevents me from using this code. For example, it prevents the expression of a string param value such as '2017'.

https://github.com/StefH/angular-odata-es5/blob/master/src/angularODataUtils.ts#L23

I propose it instead checks if the type of the value is a string, and if so, wraps it in quotes.

CustomFunction formats odata call incorrectly

Expect:
/odata/entity/functionName()

Actual:
/odata/entity('key')/functionName

Looking at the source:

 public CustomFunction(key: string, actionName: string): Observable<any> {
        return this._http.get(this.getEntityUri(key) + '/' + actionName, this.config.defaultRequestOptions).map(resp => resp.json());
    }

Passing it a key seems unneeded, functions are called on the entities so just a functionName is required.

Also looks like a copy paste bug that the second parameter should be functionName instead of actionName.

It would also be nice if it took an args array of key/value pair, but I can do a PR for that.

Saving query parameters

If I doing Odata request with parameters and then doing Delete request, all parameters from first request sended in second request.
For example:

this.odata = odataFactory.CreateService<T>(serviceName); 
// sending $top=100
this.odata.Query().Top(100).Exec();
// and here sending $top=100
this.odata.Delete(1);

Tell me, is this how it should be? I understand that Delete should be sent without parameters (except for the key parameter)

How to assign Authorization header?

Hi @StefH , how to set up ODataConfiguration so I can add an Authorization header to below query?

const query: ODataQuery<recordedCalls> = this.odata.Query().Select(...);

PrimeNGDataTableODataQueryExtensions.applyLazyLoadEvent(query, event);

query.ExecWithCount()
        .subscribe((pagedResult: ODataPagedResult<recordedCalls>) => {
            this.calls = pagedResult.data;
            this.totalRecords = pagedResult.count;
        },
        (error) => {
            console.log('getPagedData ERROR ' + error);
        });

Question : Complete example with service-url

Hi,

I want to access a odata-service with angular 2 bzw. ionic. It seems this component can make
this a little bit more comfortable.
Do you have a complete example with a
service.svc/$metadata
by using the component ?
Or is it necessary to implement the $select - urls manually ?

kind regards
michael

An in-range update of @angular/platform-browser is breaking the build 🚨

Version 4.2.2 of @angular/platform-browser just got published.

Branch Build failing 🚨
Dependency @angular/platform-browser
Current Version 4.2.1
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As @angular/platform-browser is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ

Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

Observable.throw is not a function

Hello, I'm getting the error described in the title when I'm using Exec and the url retrive a status 400 error.

A workaround to this issue was changing this line in angularODataQuery.js:

import { Observable } from 'rxjs/Observable';

To this

import { Observable } from 'rxjs/Rx';

So the whole Rx Package is imported and also the static method Observation.throw come together, but it's not the best approach.

This issue explain in details the problem and the best solution:
ReactiveX/rxjs#1866

toCommaString break Datetime comparator

Hi
The toCommaString present into this file : 'angular-odata-es5/src/angularODataOperation.ts' seems to broke the Datetime comparator.
For example:
SignatoryID eq ${this.signatory.ID} and EndDate lt ${new Date().toISOString()}
Format -> SignatoryID eq 14 and EndDate ge 2018-02-07T09:58:30.897Z
toCommaString -> SignatoryID eq 14 and EndDate ge 2018-02-07T09:58:30/897Z
The dot is replaced by a slash..

An in-range update of @angular/compiler is breaking the build 🚨

Version 4.2.2 of @angular/compiler just got published.

Branch Build failing 🚨
Dependency @angular/compiler
Current Version 4.2.1
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As @angular/compiler is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ

Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build failed Details

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

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.