Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
/bin/
/target/
/node_modules/
/build/
/build/
.idea/
/dist/
/package-lock.json
/bimserverapi.iml
/coverage/
/.nyc_output/
31 changes: 31 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
language: node_js
node_js:
- "10"

services:
- docker

before_script:
- docker pull muenchhausen/docker-bimserver
- docker run --name docker-bimserver --rm -d -p 8888:8080 muenchhausen/docker-bimserver
- docker ps -a
# wait until container is running
- |
echo "healthcheck start"
until [ $(docker ps --format "table {{.Names}}" -f health=healthy | grep docker-bimserver) ]
do
echo "healthcheck retry"
sleep 5
done
echo "healthcheck success"

# set sample user and credentials
- |
curl 'http://localhost:8888/json' --retry 3 --retry-delay 5 -H 'Origin: http://localhost:8888' \
-H 'Accept: application/json, text/javascript, */*; q=0.01' -H 'Referer: http://localhost:8888/' \
-H 'X-Requested-With: XMLHttpRequest' -H 'Connection: keep-alive' \
--data '{"request":{"interface":"AdminInterface","method":"setup","parameters":{"siteAddress":"http://localhost:8888","serverName":"","serverDescription":"","serverIcon":"/img/bimserver.png","adminName":"Administrator","adminUsername":"derk@muenchhausen.de","adminPassword":"admin"}}}' \
--compressed

script:
- npm run test
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# BIMserver-JavaScript-API
# BIMserver-JavaScript-API [![Build Status](https://travis-ci.org/muenchhausen/BIMserver-JavaScript-API.svg?branch=master)](https://travis-ci.org/muenchhausen/BIMserver-JavaScript-API)

A JavaScript API for the OpenSource BIMserver.

Expand Down
180 changes: 93 additions & 87 deletions bimserverapipromise.js → bimserverapipromise.ts
Original file line number Diff line number Diff line change
@@ -1,87 +1,93 @@
export default class BimServerApiPromise {
constructor(counter = null) {
this.isDone = false;
this.chains = [];
this.callback = null;
this.counter = counter;
}

done(callback) {
if (this.isDone) {
callback();
} else {
if (this.callback != null) {
if (this.callback instanceof Array) {
this.callback.push(callback);
} else {
this.callback = [this.callback, callback];
}
} else {
this.callback = callback;
}
}
return this;
}

inc() {
if (this.counter == null) {
this.counter = 0;
}
this.counter++;
}

dec() {
if (this.counter == null) {
this.counter = 0;
}
this.counter--;
if (this.counter === 0) {
this.done = true;
this.fire();
}
}

fire() {
if (this.isDone) {
console.log("Promise already fired, not triggering again...");
return;
}
this.isDone = true;
if (this.callback != null) {
if (this.callback instanceof Array) {
this.callback.forEach((cb) => {
cb();
});
} else {
this.callback();
}
}
}

chain(otherPromise) {
let promises;
if (otherPromise instanceof Array) {
promises = otherPromise;
} else {
promises = [otherPromise];
}
promises.forEach((promise) => {
if (!promise.isDone) {
this.chains.push(promise);
promise.done(() => {
for (let i = this.chains.length - 1; i >= 0; i--) {
if (this.chains[i] == promise) {
this.chains.splice(i, 1);
}
}
if (this.chains.length === 0) {
this.fire();
}
});
}
});
if (this.chains.length === 0) {
this.fire();
}
}
}
class BimServerApiPromise {
isDone: boolean;
chains: any[];
callback: any;
counter: any;

constructor(counter = null) {
this.isDone = false;
this.chains = [];
this.callback = null;
this.counter = counter;
}

done(callback) {
if (this.isDone) {
callback();
} else {
if (this.callback != null) {
if (this.callback instanceof Array) {
this.callback.push(callback);
} else {
this.callback = [this.callback, callback];
}
} else {
this.callback = callback;
}
}
return this;
}

inc() {
if (this.counter == null) {
this.counter = 0;
}
this.counter++;
}

dec() {
if (this.counter == null) {
this.counter = 0;
}
this.counter--;
if (this.counter === 0) {
this.isDone = true;
this.fire();
}
}

fire() {
if (this.isDone) {
console.log("Promise already fired, not triggering again...");
return;
}
this.isDone = true;
if (this.callback != null) {
if (this.callback instanceof Array) {
this.callback.forEach((cb) => {
cb();
});
} else {
this.callback();
}
}
}

chain(otherPromise) {
let promises;
if (otherPromise instanceof Array) {
promises = otherPromise;
} else {
promises = [otherPromise];
}
promises.forEach((promise) => {
if (!promise.isDone) {
this.chains.push(promise);
promise.done(() => {
for (let i = this.chains.length - 1; i >= 0; i--) {
if (this.chains[i] == promise) {
this.chains.splice(i, 1);
}
}
if (this.chains.length === 0) {
this.fire();
}
});
}
});
if (this.chains.length === 0) {
this.fire();
}
}
}
export { BimServerApiPromise };
Loading