Skip to content

Commit

Permalink
Merge pull request singnet#29 from singnet/master
Browse files Browse the repository at this point in the history
Pull from parent
  • Loading branch information
raamb authored Feb 10, 2019
2 parents 3372a0a + 52b979a commit d8cac82
Show file tree
Hide file tree
Showing 4 changed files with 303 additions and 95 deletions.
87 changes: 0 additions & 87 deletions src/components/service/BaseService.js

This file was deleted.

77 changes: 74 additions & 3 deletions src/components/service/ExampleService.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import React from 'react';
import {hasOwnDefinedProperty} from '../../util'
import BaseService from './BaseService';

export default class ExampleService extends BaseService {
export default class ExampleService extends React.Component {

constructor(props) {
super(props);
Expand All @@ -17,8 +16,63 @@ export default class ExampleService extends BaseService {
a: 0,
b: 0
};

this.isComplete = false;
this.serviceMethods = [];
this.allServices = [];
this.methodsForAllServices = [];
this.parseProps(props);
}

componentWillReceiveProps(nextProps) {
if(this.isComplete !== nextProps.isComplete) {
this.parseProps(nextProps);
}
}

parseProps(nextProps) {
this.isComplete = nextProps.isComplete;
if (!this.isComplete) {
this.parseServiceSpec(nextProps.serviceSpec);
} else {
if (typeof nextProps.response !== 'undefined') {
if (typeof nextProps.response === 'string') {
this.state.response = nextProps.response;
} else {
this.state.response = nextProps.response.value;
}
}
}
}

parseServiceSpec(serviceSpec) {
const packageName = Object.keys(serviceSpec.nested).find(key =>
typeof serviceSpec.nested[key] === "object" &&
hasOwnDefinedProperty(serviceSpec.nested[key], "nested"));

var objects = undefined;
var items = undefined;
if (typeof packageName !== 'undefined') {
items = serviceSpec.lookup(packageName);
objects = Object.keys(items);
} else {
items = serviceSpec.nested;
objects = Object.keys(serviceSpec.nested);
}

this.allServices.push("Select a service");
this.methodsForAllServices = [];
objects.map(rr => {
if (typeof items[rr] === 'object' && items[rr] !== null && items[rr].hasOwnProperty("methods")) {
this.allServices.push(rr);
this.methodsForAllServices.push(rr);

var methods = Object.keys(items[rr]["methods"]);
methods.unshift("Select a method");
this.methodsForAllServices[rr] = methods;
}
})
}

handleFormUpdate(event) {
this.setState({
Expand All @@ -31,7 +85,24 @@ export default class ExampleService extends BaseService {
this.setState({
serviceName: strService
});
super.handleServiceName(strService);
this.serviceMethods.length = 0;
if (typeof strService !== 'undefined' && strService !== 'Select a service') {
let data = Object.values(this.methodsForAllServices[strService]);
if (typeof data !== 'undefined') {
this.serviceMethods= data;
}
}
}

onKeyPressvalidator(event) {
const keyCode = event.keyCode || event.which;
if (!(keyCode == 8 || keyCode == 46) && (keyCode < 48 || keyCode > 57)) {
event.preventDefault()
} else {
let dots = event.target.value.split('.');
if (dots.length > 1 && keyCode == 46)
event.preventDefault()
}
}

submitAction() {
Expand Down
9 changes: 4 additions & 5 deletions src/components/service/ServiceMappings.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Zeta36ChessAlphaZero from './Zeta36ChessAlphaZero.js';
import NamedEntityRecognitionService from "./NamedEntityRecognitionService.js";
import SentimentAnalysisService from "./SentimentAnalysisService";
import TimeSeriesAnomalyDiscoveryService from "./TimeSeriesAnomalyDiscoveryService.js"
import VisualQAOpencog from './VisualQAOpencog.js';
import MosesService from "./MosesService";

import DefaultService from './DefaultService.js';
Expand All @@ -29,6 +30,7 @@ export default class SampleServices {
this.serviceOrgIDToComponent[this.generateUniqueID("snet", "s2vt-video-captioning")] = S2VTVideoCaptioning;
this.serviceOrgIDToComponent[this.generateUniqueID("snet", "yolov3-object-detection")] = YOLOv3ObjectDetection;
this.serviceOrgIDToComponent[this.generateUniqueID("snet", "zeta36-chess-alpha-zero")] = Zeta36ChessAlphaZero;
this.serviceOrgIDToComponent[this.generateUniqueID("snet", "opencog-vqa")] = VisualQAOpencog;
this.serviceOrgIDToComponent[this.generateUniqueID("snet", "named-entity-recognition")] = NamedEntityRecognitionService;
this.serviceOrgIDToComponent[this.generateUniqueID("snet", "sentiment-analysis")] = SentimentAnalysisService;
this.serviceOrgIDToComponent[this.generateUniqueID("snet", "time-series-anomaly-discovery")] = TimeSeriesAnomalyDiscoveryService;
Expand All @@ -40,17 +42,14 @@ export default class SampleServices {
generateUniqueID(orgId,serviceId) {
return orgId + "__$%^^%$__" + serviceId;
}
componentWillReceiveProps(nextProps) {
if(this.isComplete !== nextProps.isComplete) {
this.parseProps(nextProps);
}
}

getComponent(orgId, serviceId) {
let component = this.serviceOrgIDToComponent[this.generateUniqueID(orgId, serviceId)];
if(typeof component === 'undefined') {
component = DefaultService;
}


return component;
}
}
Loading

0 comments on commit d8cac82

Please sign in to comment.