Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit 09d3ed1

Browse files
Added color picker, readme and various other fixes
1 parent d1bcc7d commit 09d3ed1

19 files changed

+564
-53
lines changed

README.md

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,62 @@
1-
# c8y-3d-collada-widget
1+
# Cumulocity IoT 3D Collada Widget
2+
3+
This is a runtime widget to view a 3D collada model (*.dae) in Cumulocity IoT.
4+
5+
<img src="/assets/img-preview.png" />
6+
7+
### Features
8+
* Supports measurements from a single device
9+
* Allows background color customization.
10+
* Allows to configure realtime device measurement for model movements.
11+
* Allows to upload custom collada(.dae) model file.
12+
13+
### Installation - for the dashboards using Runtime Widget Loader
14+
1. Download the latest `3dcollada-widget-{version}.zip` file from the Releases section.
15+
2. Make sure you have Runtime Widget Loader installed on your Cockpit or App Builder app.
16+
3. Open a dashboard.
17+
4. Click `more...`.
18+
5. Select `Install Widget` and follow the instructions.
19+
20+
### Deployment - as part of the Cumulocity IoT Cockpit application
21+
1. Clone the repository on your local machine using `git clone https://github.com/SoftwareAG/cumulocity-3d-collada-widget.git`.
22+
2. Run `npm install` to install the module dependencies.
23+
3. Run `c8ycli build` to build the cockpit application.
24+
4. Run `c8ycli deploy` and follow the instructions to deploy the cockpit application on your tenant. This will include the widget also.
25+
26+
### Configuration - to view the 3d collada model in the widget
27+
1. Make sure you have successfully installed or deployed the widget.
28+
2. Click on `Add widget`.
29+
3. Choose `3d collada` widget.
30+
4. `Title` is the title of widget. Provide a relevant name. You may choose to hide this. Go to `Appearance` tab and choose `Hidden` under `Widget header style`.
31+
5. Select the `device`.
32+
6. `3d collada file(*.dae)` is to upload the 3d collada model file (*.dae) into inventory binary. Please wait for it to finish the upload.
33+
7. `Variables` is to declare variables with a constant value or map them to the realtime device measurement series. Choose Target as None and provide the constant value or choose Target as Device and then select a measurment series.
34+
8. `Properties` is to define values for the model properties. You can provide a value as an mathematical expression using the variables defined earlier.
35+
9. `Background color (in hex)` allows you to set a custom background color using the color picker.
36+
10. `Show grid` allows you to show or hide the grid.
37+
11. Click `Save` to add the widget on the dashboard.
38+
12. In case you see unexpected results on the widget, refer to browser console to see if there are error logs.
39+
40+
### Development - to do the enhancements and testing locally
41+
1. Clone the repository on local machine using `git clone https://github.com/SoftwareAG/cumulocity-3d-collada-widget.git`.
42+
2. Run `npm install` to download the module dependencies.
43+
3. Install c8ycli `npm install -g @c8y/cli` if not already.
44+
4. Run `c8ycli server -u https://your_tenant_url` to start the server.
45+
5. Go to `http://localhost:9000/apps/cockpit/` in the browser to view and test your changes.
46+
6. (Optional) push the changes back to this repository.
47+
48+
### Build - to create a new build for the Runtime Widget Loader
49+
1. Finish the development and testing on your local machine.
50+
2. Run `gulp` to start the build process. Run `npm install -g gulp` to install gulp if not already.
51+
3. Use `widget.zip` file in the `dist` folder as a distribution.
52+
53+
------------------------------
54+
55+
These tools are provided as-is and without warranty or support. They do not constitute part of the Software AG product suite. Users are free to use, fork and modify them, subject to the license agreement. While Software AG welcomes contributions, we cannot guarantee to include every contribution in the master project.
56+
57+
------------------------------
58+
59+
For more information you can Ask a Question in the [TECHcommunity Forums](http://tech.forums.softwareag.com/techjforum/forums/list.page?product=cumulocity).
60+
61+
62+
You can find additional information in the [Software AG TECHcommunity](http://techcommunity.softwareag.com/home/-/product/name/cumulocity).

app.module.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ import { ReportsModule } from '@c8y/ngx-components/reports';
1515
import { SensorPhoneModule } from '@c8y/ngx-components/sensor-phone';
1616
import { ColladaWidget } from './src/collada-widget/collada-widget.component';
1717
import { ColladaWidgetConfig } from './src/collada-widget/collada-widget-config.component';
18+
import { ColorPaletteComponent } from './src/collada-widget/color-picker/color-palette/color-palette-component';
19+
import { ColorSliderComponent } from './src/collada-widget/color-picker/color-slider/color-slider-component';
20+
import { ColorPickerComponent } from './src/collada-widget/color-picker/color-picker-component';
1821

1922
@NgModule({
2023
imports: [
@@ -29,7 +32,7 @@ import { ColladaWidgetConfig } from './src/collada-widget/collada-widget-config.
2932
SensorPhoneModule,
3033
UpgradeModule
3134
],
32-
declarations: [ColladaWidget, ColladaWidgetConfig],
35+
declarations: [ColladaWidget, ColladaWidgetConfig, ColorPickerComponent, ColorSliderComponent, ColorPaletteComponent],
3336
entryComponents: [ColladaWidget, ColladaWidgetConfig],
3437
providers: [{
3538
provide: HOOK_COMPONENTS,
@@ -38,7 +41,7 @@ import { ColladaWidgetConfig } from './src/collada-widget/collada-widget-config.
3841
{
3942
id: 'com.softwareag.globalpresales.colladawidget',
4043
label: '3D Collada',
41-
description: 'This is a 3D Collada Widget for Cumulocity IoT.',
44+
description: 'A runtime widget to view a 3d collada model (*.dae) in Cumulocity IoT. It has been developed by Global Presales team.',
4245
component: ColladaWidget,
4346
configComponent: ColladaWidgetConfig,
4447
previewImage: require("./assets/img-preview.png")

package-lock.json

Lines changed: 1 addition & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"@angular/compiler": "8.2.13",
2424
"@angular/core": "8.2.13",
2525
"@angular/forms": "8.2.13",
26+
"@angular/http": "7.2.15",
2627
"@angular/platform-browser": "8.2.13",
2728
"@angular/platform-browser-dynamic": "8.2.13",
2829
"@angular/router": "8.2.13",
@@ -35,7 +36,6 @@
3536
"lodash": "4.17.20",
3637
"mathjs": "9.3.2",
3738
"rxjs": "6.4.0",
38-
"stream-to-blob": "2.0.1",
3939
"three": "0.127.0",
4040
"url-search-params-polyfill": "6.0.0",
4141
"zone.js": "0.9.1"

src/collada-widget/collada-widget-config.component.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,12 @@ td, th {
55

66
div.separator {
77
height: 20px;
8+
}
9+
10+
.showColorPicker {
11+
display: block;
12+
}
13+
14+
.hideColorPicker {
15+
display: none;
816
}

src/collada-widget/collada-widget-config.component.html

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<c8y-form-group>
33

44
<!-- Model File -->
5-
<label for="model-file" translate>3D Collada File (*.DAE)</label>
5+
<label for="model-file" translate>3d collada file (*.dae)</label>
66
<input type="text" class="form-control" [(ngModel)]="widgetInfo.binaryName" readonly />
77
<input type="file" class="form-control" name="model-file" (change)="uploadModelFile($event.target.files)" accept=".dae,model/vnd.collada+xml" />
88
<div>{{modelFileUploadMessage}}</div>
@@ -107,13 +107,14 @@
107107
<div class="row">
108108
<div class="col-lg-6">
109109
<!-- Background Color -->
110-
<label for="background-color" translate>Background Color</label>
111-
<input type="text" class="form-control" name="background-color" [(ngModel)]="widgetInfo.advanced.backgroundColor" (change)="updateConfig()" />
110+
<label for="background-color" translate>Background color (in hex)</label>
111+
<input type="text" class="form-control" name="background-color" [(ngModel)]="widgetInfo.advanced.backgroundColor" (change)="updateConfig()" (click)="openBackgroundColorPicker()" />
112+
<app-color-picker [ngClass]="backgroundColorPickerClosed? 'hideColorPicker' : 'showColorPicker'" (colorPickerClosed)="closeBackgroundColorPicker()" (colorSet)="setSelectedColorForBackground($event)" ></app-color-picker>
112113
</div>
113114
<div class="col-lg-6">
114115
<!-- Show Grid -->
115116
<label for="show-grid" translate>
116-
Show Grid
117+
Show grid
117118
</label>
118119
<select class="form-control" name="show-grid" [(ngModel)]="widgetInfo.advanced.showGrid" (change)="updateConfig()">
119120
<option value = "false" [selected]="widgetInfo.advanced.showGrid === 'false'">No</option>

src/collada-widget/collada-widget-config.component.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ import { ColladaLoader } from 'three/examples/jsm/loaders/ColladaLoader.js';
3131
export class ColladaWidgetConfig implements OnInit {
3232
@Input() config: any = {};
3333

34+
backgroundColorPickerClosed : boolean = true;
35+
3436
modelFile: File = null;
3537
modelFileUploadMessage: string;
3638
private measurementSeriesLoaded: boolean = false;
@@ -281,4 +283,18 @@ export class ColladaWidgetConfig implements OnInit {
281283
_.set(this.config, 'customwidgetdata', this.widgetInfo);
282284
}
283285

286+
setSelectedColorForBackground(value: string) {
287+
value = value.substring(0,7);
288+
this.widgetInfo.advanced.backgroundColor = value;
289+
this.updateConfig();
290+
}
291+
292+
closeBackgroundColorPicker() {
293+
this.backgroundColorPickerClosed = true;
294+
}
295+
296+
openBackgroundColorPicker() {
297+
this.backgroundColorPickerClosed = false;
298+
}
299+
284300
}

src/collada-widget/collada-widget.module.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,27 @@ import { NgModule } from '@angular/core';
22
import { CoreModule, HOOK_COMPONENTS } from '@c8y/ngx-components';
33
import { ColladaWidget } from './collada-widget.component';
44
import { ColladaWidgetConfig } from './collada-widget-config.component';
5-
import { HttpClientModule } from '@angular/common/http';
5+
import { ColorPickerComponent } from './color-picker/color-picker-component';
6+
import { ColorSliderComponent } from './color-picker/color-slider/color-slider-component';
7+
import { ColorPaletteComponent } from './color-picker/color-palette/color-palette-component';
68

79
@NgModule({
810
imports: [
9-
CoreModule,
10-
HttpClientModule
11+
CoreModule
1112
],
12-
declarations: [ColladaWidget, ColladaWidgetConfig],
13+
declarations: [ColladaWidget, ColladaWidgetConfig, ColorPickerComponent, ColorSliderComponent, ColorPaletteComponent],
1314
entryComponents: [ColladaWidget, ColladaWidgetConfig],
1415
providers: [{
1516
provide: HOOK_COMPONENTS,
1617
multi: true,
17-
useValue: [
18-
{
19-
id: 'com.softwareag.globalpresales.colladawidget',
20-
label: '3D Collada',
21-
description: 'This is a 3D Collada Widget for Cumulocity IoT.',
22-
component: ColladaWidget,
23-
configComponent: ColladaWidgetConfig,
24-
previewImage: require("~assets/img-preview.png")
25-
}
26-
]
18+
useValue: {
19+
id: 'com.softwareag.globalpresales.colladawidget',
20+
label: '3d collada',
21+
description: 'A runtime widget to view a 3d collada model (*.dae) in Cumulocity IoT. It has been developed by Global Presales team.',
22+
component: ColladaWidget,
23+
configComponent: ColladaWidgetConfig,
24+
previewImage: require("~assets/img-preview.png")
25+
}
2726
}],
2827
})
2928
export class ColladaWidgetAppModule {}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.color-palette:hover {
2+
cursor: pointer;
3+
}
4+
5+
:host {
6+
width: 150px;
7+
height: 150px;
8+
display: block;
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<canvas
2+
#canvas
3+
class="color-palette"
4+
width="150"
5+
height="150"
6+
(mousedown)="onMouseDown($event)"
7+
(mousemove)="onMouseMove($event)"
8+
>
9+
</canvas>

0 commit comments

Comments
 (0)