|
1 | | -# NativeScript DropDown widget |
2 | | -[](https://travis-ci.org/PeterStaev/NativeScript-Drop-Down) |
3 | | -[](https://www.npmjs.com/package/nativescript-drop-down) |
4 | | -[](https://www.npmjs.com/package/nativescript-drop-down) |
5 | | -[](https://www.npmjs.com/package/nativescript-drop-down) |
| 1 | +# NativeScript Telerik Reporting |
| 2 | +[](https://travis-ci.org/PeterStaev/nativescript-telerik-reporting) |
| 3 | +[](https://www.npmjs.com/package/nativescript-telerik-reporting) |
| 4 | +[](https://www.npmjs.com/package/nativescript-telerik-reporting) |
| 5 | +[](https://www.npmjs.com/package/nativescript-telerik-reporting) |
6 | 6 |
|
7 | | -A NativeScript DropDown widget. The DropDown displays items from which the user can select one. For iOS it wraps up a [UILabel](https://developer.apple.com/reference/uikit/uilabel) with an `inputView` set to an [UIPickerView](https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UIPickerView_Class/index.html) which displays the items. For Android it wraps up the [Spinner](http://developer.android.com/reference/android/widget/Spinner.html) widget. |
| 7 | +A NativeScript plugin for easy access to [Telerik Rporting REST API](https://docs.telerik.com/reporting/telerik-reporting-rest-api). |
8 | 8 |
|
9 | | -## Screenshot |
10 | | - |
11 | 9 |
|
12 | 10 | ## Installation |
13 | 11 | Run the following command from the root of your project: |
14 | 12 |
|
15 | | -`tns plugin add nativescript-drop-down` |
| 13 | +`tns plugin add nativescript-telerik-reporting` |
16 | 14 |
|
17 | | -This command automatically installs the necessary files, as well as stores nativescript-drop-down as a dependency in your project's package.json file. |
| 15 | +This command automatically installs the necessary files, as well as stores nativescript-telerik-reporting as a dependency in your project's package.json file. |
18 | 16 |
|
19 | 17 | ## Configuration |
20 | 18 | There is no additional configuration needed! |
21 | 19 |
|
22 | 20 | ## API |
23 | 21 |
|
24 | | -### Events |
25 | | -* **opened** |
26 | | -Triggered when the DropDown is opened. |
| 22 | +### `ReportingClient` |
| 23 | +#### Methods |
27 | 24 |
|
28 | | -* **closed** |
29 | | -Triggered when the DropDown is closed. |
| 25 | +### `ReportingInstance` |
| 26 | +#### Methods |
30 | 27 |
|
31 | | -* **selectedIndexChanged** |
32 | | -Triggered when the user changes the selection in the DropDown |
33 | | - |
34 | | -### Static Properties |
35 | | -* **openedEvent** - *String* |
36 | | -String value used when hooking to opened event. |
37 | | - |
38 | | -* **closedEvent** - *String* |
39 | | -String value used when hooking to closed event. |
40 | | - |
41 | | -* **selectedIndexChangedEvent** - *String* |
42 | | -String value used when hooking to selectedIndexChanged event. |
43 | | - |
44 | | -### Instance Properties |
45 | | -* **ios** - *[UILabel](https://developer.apple.com/reference/uikit/uilabel)* |
46 | | -Gets the native iOS view that represents the user interface for this component. Valid only when running on iOS. |
47 | | - |
48 | | -* **android** - *[android.widget.Spinner](http://developer.android.com/reference/android/widget/Spinner.html)* |
49 | | -Gets the native android widget that represents the user interface for this component. Valid only when running on Android OS. |
50 | | - |
51 | | -* **items** - *Array | ItemsSource* |
52 | | -Gets or sets the items collection of the DropDown. The items property can be set to an array or an object defining length and getItem(index) method. |
53 | | - |
54 | | -* **selectedIndex** - *Number* |
55 | | -Gets or sets the selected index of the DropDown. |
56 | | - |
57 | | -* **hint** - *String* |
58 | | -Gets or sets the hint for the DropDown. |
59 | | - |
60 | | -* **isEnabled** - *boolean* |
61 | | -Gets or sets whether the drop down is enabled. If you want to apply a specific style you can use the `:disabled` pseudo css selector. |
62 | | - |
63 | | -* **accessoryViewVisible** - *boolean* (Default: true) |
64 | | -Gets/sets whether there will be an accessory view (toolbar with Done button) under iOS. Valid only when running on iOS. |
65 | | - |
66 | | -### Methods |
67 | | -* **open(): void** |
68 | | -Opens the drop down. |
69 | | - |
70 | | -* **close(): void** |
71 | | -Closes the drop down. |
| 28 | +### `ReportingDocument` |
| 29 | +#### Methods |
72 | 30 |
|
73 | 31 | ## Usage |
74 | | -You need to add `xmlns:dd="nativescript-drop-down"` to your page tag, and then simply use `<dd:DropDown/>` in order to add the widget to your page. |
75 | | - |
76 | | -```xml |
77 | | -<!-- test-page.xml --> |
78 | | -<Page xmlns="http://schemas.nativescript.org/tns.xsd" loaded="pageLoaded" xmlns:dd="nativescript-drop-down"> |
79 | | - <GridLayout rows="auto, auto, *" columns="auto, *"> |
80 | | - <dd:DropDown items="{{ items }}" selectedIndex="{{ selectedIndex }}" |
81 | | - opened="dropDownOpened" closed="dropDownClosed" |
82 | | - selectedIndexChanged="dropDownSelectedIndexChanged" |
83 | | - row="0" colSpan="2" /> |
84 | | - <Label text="Selected Index:" row="1" col="0" fontSize="18" verticalAlignment="bottom"/> |
85 | | - <TextField text="{{ selectedIndex }}" row="1" col="1" /> |
86 | | - </GridLayout> |
87 | | -</Page> |
88 | | -``` |
89 | | - |
90 | | -```ts |
91 | | -// test-page.ts |
92 | | -import observable = require("data/observable"); |
93 | | -import observableArray = require("data/observable-array"); |
94 | | -import pages = require("ui/page"); |
95 | | -import { SelectedIndexChangedEventData } from "nativescript-drop-down"; |
96 | | - |
97 | | -var viewModel: observable.Observable; |
98 | | - |
99 | | -export function pageLoaded(args: observable.EventData) { |
100 | | - var page = <pages.Page>args.object; |
101 | | - var items = new observableArray.ObservableArray(); |
102 | | - |
103 | | - viewModel = new observable.Observable(); |
104 | | - |
105 | | - for (var loop = 0; loop < 20; loop++) { |
106 | | - items.push("Item " + loop.toString()); |
107 | | - } |
108 | | - |
109 | | - viewModel.set("items", items); |
110 | | - viewModel.set("selectedIndex", 15); |
111 | | - |
112 | | - page.bindingContext = viewModel; |
113 | | -} |
114 | | - |
115 | | -export function dropDownOpened(args: EventData) { |
116 | | - console.log("Drop Down opened"); |
117 | | -} |
118 | | - |
119 | | -export function dropDownClosed(args: EventData) { |
120 | | - console.log("Drop Down closed"); |
121 | | -} |
122 | | - |
123 | | -export function dropDownSelectedIndexChanged(args: SelectedIndexChangedEventData) { |
124 | | - console.log(`Drop Down selected index changed from ${args.oldIndex} to ${args.newIndex}`); |
125 | | -} |
126 | | -``` |
127 | | - |
128 | | -## Usage in Angular |
129 | | - |
130 | | -##### Migration to 3.0+ |
131 | | - |
132 | | -- Remove: |
133 | | -```typescript |
134 | | -registerElement("DropDown", () => require("nativescript-drop-down/drop-down").DropDown);` |
135 | | -``` |
136 | | -- Import `DropDownModule` in `NgModule`: |
137 | | -```typescript |
138 | | -import { DropDownModule } from "nativescript-drop-down/angular"; |
139 | | -//...... |
140 | | -@NgModule({ |
141 | | - //...... |
142 | | - imports: [ |
143 | | - //...... |
144 | | - DropDownModule, |
145 | | - //...... |
146 | | - ], |
147 | | - //...... |
148 | | -}) |
149 | | -``` |
| 32 | +A typical usage scenario is when you want to generate a report on your server and the download the file in an appropriate format (for example a PDF document). Below is an example how you can make this. You start by creating a client with your server's URL. Then you register your client, create an instance and a document. Finally you download the document to the mobile device. |
150 | 33 |
|
151 | | -##### Example Usage |
152 | 34 | ```ts |
153 | | -// main.ts |
154 | | -import { NgModule } from "@angular/core"; |
155 | | -import { NativeScriptModule } from "nativescript-angular/nativescript.module"; |
156 | | -import { platformNativeScriptDynamic } from "nativescript-angular/platform"; |
157 | | -import { DropDownModule } from "nativescript-drop-down/angular"; |
158 | | -import { AppComponent } from "./app.component"; |
159 | | -
|
160 | | -@NgModule({ |
161 | | - declarations: [ AppComponent ], |
162 | | - bootstrap: [ AppComponent ], |
163 | | - imports: [ |
164 | | - NativeScriptModule, |
165 | | - DropDownModule, |
166 | | - ], |
167 | | -}) |
168 | | -class AppComponentModule { |
169 | | -} |
170 | | -
|
171 | | -platformNativeScriptDynamic().bootstrapModule(AppComponentModule); |
172 | | -``` |
173 | | - |
174 | | -```html |
175 | | -<!-- app.component.html --> |
176 | | -<StackLayout> |
177 | | - <GridLayout rows="auto, auto, *" |
178 | | - columns="auto, *"> |
179 | | - <DropDown #dd |
180 | | - backroundColor="red" |
181 | | - [items]="items" |
182 | | - [(ngModel)]="selectedIndex" |
183 | | - (selectedIndexChanged)="onchange($event)" |
184 | | - (opened)="onopen()" |
185 | | - (closed)="onclose()" |
186 | | - row="0" |
187 | | - colSpan="2"></DropDown> |
188 | | - <Label text="Selected Index:" |
189 | | - row="1" |
190 | | - col="0" |
191 | | - fontSize="18" |
192 | | - verticalAlignment="bottom"></Label> |
193 | | - <TextField [text]="selectedIndex" |
194 | | - row="1" |
195 | | - col="1"></TextField> |
196 | | - </GridLayout> |
197 | | -</StackLayout> |
198 | | -``` |
199 | | - |
200 | | -```ts |
201 | | -// app.component.ts |
202 | | -import { Component } from "@angular/core"; |
203 | | -import { SelectedIndexChangedEventData } from "nativescript-drop-down"; |
204 | | -
|
205 | | -@Component({ |
206 | | - selector: "my-app", |
207 | | - templateUrl:"app.component.html", |
208 | | -}) |
209 | | -export class AppComponent { |
210 | | - public selectedIndex = 1; |
211 | | - public items: Array<string>; |
212 | | - |
213 | | - constructor() { |
214 | | - this.items = []; |
215 | | - for (var i = 0; i < 5; i++) { |
216 | | - this.items.push("data item " + i); |
217 | | - } |
218 | | - } |
219 | | -
|
220 | | - public onchange(args: SelectedIndexChangedEventData) { |
221 | | - console.log(`Drop Down selected index changed from ${args.oldIndex} to ${args.newIndex}`); |
222 | | - } |
223 | | -
|
224 | | - public onopen() { |
225 | | - console.log("Drop Down opened."); |
226 | | - } |
227 | | -
|
228 | | - public onclose() { |
229 | | - console.log("Drop Down closed."); |
230 | | - } |
231 | | -} |
232 | | -``` |
233 | | - |
234 | | -## Working with value and display members |
235 | | -It is a common case that you want to have one thing displayed in the drop down and then get some backend value |
236 | | -tied to the tex. For example drop down with states you might want tos how the full state name (i.e. Florida) |
237 | | -and then when working with your backend you want to use the state code (i.e. FL). The Drop Down items property can be |
238 | | -set to either Array of objects or a custom object that implements `getItem(index: number): any` function and `length` proerty. With versionn 3.0 of the plugin it has a built in class that helps you with this scenario: |
239 | | - |
240 | | -```ts |
241 | | -import { ValueList } from "nativescript-drop-down"; |
242 | | -``` |
243 | | - |
244 | | -Then you can set the `items` property of the DropDown to an instance of ValueList: |
245 | | -```ts |
246 | | -let dd = page.getViewById<DropDown>("dd"); |
247 | | -let itemSource = new ValueList<string>([ |
248 | | - { value: "FL", display: "Florida" }, |
249 | | - { value: "MI", display: "Michigan" } |
250 | | -]); |
251 | | -dd.items = itemSource; |
252 | | -``` |
253 | | - |
254 | | -This enables you to do things like: |
255 | | -1.If you want to select an item in the DropDown by its backend value (for example FL), you can do this with: |
256 | | -```ts |
257 | | -dd.selectedIndex = itemSource.getIndex("FL"); |
258 | | -``` |
259 | | -2.You can get the backend value of what the user selected using: |
260 | | -```ts |
261 | | -let selectedValue = itemSource.getValue(dd.selectedIndex); |
262 | | -``` |
263 | | - |
264 | | -## Working with Webpack+Uglify |
265 | | -In case you are uing webpack and also are minifying/uglifying your code, there are some specific names that should be excluded from the uglification for the widget to work properly. The DropDown widget exports those and you need to add them to the mangle exclude option of the uglifyjs plugin in the `webpack.common.js` file: |
266 | | -```js |
267 | | -var dropDownMangleExcludes = require("nativescript-drop-down/uglify-mangle-excludes").default; |
268 | | -//...... |
269 | | -module.exports = function (platform, destinationApp) { |
270 | | - //...... |
271 | | - if (process.env.npm_config_uglify) { |
272 | | - plugins.push(new webpack.LoaderOptionsPlugin({ |
273 | | - minimize: true |
274 | | - })); |
275 | | -
|
276 | | - //Work around an Android issue by setting compress = false |
277 | | - var compress = platform !== "android"; |
278 | | - plugins.push(new webpack.optimize.UglifyJsPlugin({ |
279 | | - mangle: { |
280 | | - except: nsWebpack.uglifyMangleExcludes.concat(dropDownMangleExcludes), |
281 | | - }, |
282 | | - compress: compress, |
283 | | - })); |
284 | | - } |
285 | | - //...... |
286 | | -} |
| 35 | +const req: ReportSource = { |
| 36 | + report: "Telerik.Reporting.Examples.CSharp.Invoice, CSharp.ReportLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", |
| 37 | + parameterValues: { |
| 38 | + OrderNumber: "SO51081", |
| 39 | + ForYear: 2003, |
| 40 | + ForMonth: 7, |
| 41 | + }, |
| 42 | +}; |
| 43 | +const reportingClient = new ReportingClient({ serverUrl: "https://....." }); |
| 44 | +reportingClient.register() |
| 45 | + .then(() => reportingClient.createInstance(req)) |
| 46 | + .then((instance) => { |
| 47 | + instance.createDocument({ format: documentFormat } as any).then((document) => { |
| 48 | + document.download().then((file) => { |
| 49 | + utils.ios.openFile(file.path); |
| 50 | + viewModel.set("isBusyIn", false); |
| 51 | + |
| 52 | + document.destroy() |
| 53 | + .then(() => instance.destroy()) |
| 54 | + .then(() => reportingClient.unregister); |
| 55 | + }); |
| 56 | + }); |
| 57 | + }); |
287 | 58 | ``` |
| 59 | +It is really important to remember to call `destroy()` for your instances and documents and to `unregister()` your client as this frees up resources on the server. Also it is a good idea to reuse clients/instances whenever possible. |
288 | 60 |
|
289 | 61 | ## Demos |
290 | | -This repository includes both Angular and plain NativeScript demos. In order to run those execute the following in your shell: |
| 62 | +This repository plain NativeScript demo. In order to run those execute the following in your shell: |
291 | 63 | ```shell |
292 | | -$ git clone https://github.com/peterstaev/nativescript-drop-down |
293 | | -$ cd nativescript-drop-down |
| 64 | +$ git clone https://github.com/peterstaev/nativescript-telerik-reporting |
| 65 | +$ cd nativescript-telerik-reporting |
294 | 66 | $ npm install |
295 | 67 | $ npm run demo-ios |
296 | 68 | ``` |
297 | | -This will run the plain NativeScript demo project on iOS. If you want to run it on Android simply use the `-android` instead of the `-ios` sufix. |
298 | | - |
299 | | -If you want to run the Angular demo simply use the `demo-ng-` prefix instead of `demo-`. |
| 69 | +This will run the plain NativeScript demo project on iOS. If you want to run it on Android simply use the `-android` instead of the `-ios` sufix. |
300 | 70 |
|
301 | 71 |
|
302 | 72 | ## Donate |
|
0 commit comments