Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drag n drop #21

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
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
29 changes: 29 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
FROM nginx:1.13.0-alpine

# install console and node
RUN apk add --no-cache bash=4.3.46-r5 &&\
apk add --no-cache libressl-dev qt-dev &&\
apk add --no-cache nodejs &&\
apk add --no-cache git

# install npm ( in separate dir due to docker cache)
ADD package.json /tmp/npm_inst/package.json
RUN cd /tmp/npm_inst &&\
npm install &&\
mkdir -p /tmp/app &&\
mv /tmp/npm_inst/node_modules /tmp/app/

# build and publish application
ADD . /tmp/app
RUN cd /tmp/app &&\
npm run build &&\
mv ./dist/* /usr/share/nginx/html/

# clean
RUN rm -Rf /tmp/npm_inst &&\
rm -Rf /tmp/app &&\
rm -Rf /root/.npm &&\
apk del nodejs

# this is for virtual host purposes
EXPOSE 80
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "npm run updateBuild && ng serve",
"start": "npm run updateBuild && ng serve -H 0.0.0.0",
"build": "ng build && npm run updateBuild",
"test": "ng test",
"lint": "ng lint",
Expand All @@ -31,9 +31,10 @@
"hammerjs": "^2.0.8",
"mkdirp": "^0.5.1",
"moment": "2.18.0",
"ng-drag-drop": "^4.0.0",
"ng2-ace-editor": "^0.2.3",
"ng2-bootstrap-modal": "^1.0.1",
"ng2-openmrs-formentry": "git+https://github.com/enyachoke/ng2-opemmrs-formentry.git#2.4.10",
"ng2-openmrs-formentry": "git+https://github.com/AMPATH/ng2-opemmrs-formentry.git#2.6.0-beta",
"ngx-bootstrap": "^1.9.3",
"ngx-clipboard": "^8.0.4",
"ngx-cookie": "^1.0.0",
Expand Down
36 changes: 34 additions & 2 deletions src/app/Services/fetch-all-forms.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { SessionStorageService } from './session-storage.service';
import { FetchFormDetailService } from './fetch-form-detail.service';
import { LocalStorageService } from './local-storage.service';
import { Subject, Observable, BehaviorSubject} from 'rxjs';
import { FormListService } from './form-list.service';

@Injectable()
export class FetchAllFormsService {

Expand All @@ -23,7 +25,11 @@ constructor(private http: Http,
private ls: LocalStorageService,
private router: Router,
private auth: AuthenticationService,
private fd: FetchFormDetailService,
private formListService: FormListService) {

private fd: FetchFormDetailService) {

this.allPOCFormsSchemas = new BehaviorSubject(ls.getObject('POC_FORM_SCHEMAS'));
auth.getBaseUrl().subscribe((baseUrl) => this.baseUrl = baseUrl);
auth.getCredentialsSubject().subscribe((credentials) => {
Expand All @@ -35,7 +41,8 @@ constructor(private http: Http,


fetchAllPOCForms() {
const v = 'custom:(uuid,name,encounterType:(uuid,name),version,published,resources:(uuid,name,dataType,valueReference))';

const v = 'custom:(uuid,name,encounterType:(uuid,name),version,published,retired,resources:(uuid,name,dataType,valueReference))';
return this.http.get(`${this.baseUrl}/ws/rest/v1/form?q=POC&v=${v}`, {headers: this.headers}).map(
data => this.forms = data.json())
.catch((e) => {
Expand Down Expand Up @@ -81,6 +88,31 @@ constructor(private http: Http,
return this.allPOCFormsSchemas;
}

getPOCSameFormsDifferentVersions(formMetadata: any): Observable<any[]> {
const sameFormsDifferentVersion = [];
return this.fetchAllPOCForms().switchMap((POCForms: any) => {
const forms = _.cloneDeep(POCForms.results); // currently only poc forms version 1
const formName = this.formListService.removeVersionInformation(formMetadata.name);
const formsWithoutVersionedNames = this.formListService.removeVersionInformationFromForms(forms);
formsWithoutVersionedNames.forEach(($form) => {
if ($form.name === formName) {
sameFormsDifferentVersion.push($form);
}
});

return Observable.of(sameFormsDifferentVersion);
});
}


getLatestPublishedVersion(sameFormsDifferentVersion: any[], formUuidToBePublished: any) {
let form: any = {};
if (!_.isEmpty(sameFormsDifferentVersion)) {
sameFormsDifferentVersion.forEach((_form) => {
if (_form.published && _form.uuid !== formUuidToBePublished) {
form = _form; }});
return form;
}}}
// fetchAllPOCFormsSchemas(metadatas:any){
// let promises:Promise<any>[] = []
// // _.each(metadatas,(metadata:any) => {
Expand Down Expand Up @@ -110,4 +142,4 @@ constructor(private http: Http,

// });
// }
}

58 changes: 27 additions & 31 deletions src/app/Services/fetch-form-detail.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,38 @@ import 'rxjs/add/operator/toPromise';
@Injectable()
export class FetchFormDetailService {

private schema: Object = {}
private referencedForms: Array < Object >= []
private _rawSchema: Object = {}
private referencedFormsSchemasSubject: BehaviorSubject < any[] >= new BehaviorSubject([])
private referencedFormsDetailsSubject: BehaviorSubject < any[] > = new BehaviorSubject < any[] > ([]) //formName,alias,uuid
private schema: Object = {};
private referencedForms: Array < Object >= [];
private _rawSchema: Object = {};
private referencedFormsSchemasSubject: BehaviorSubject < any[] >= new BehaviorSubject([]);
private referencedFormsDetailsSubject: BehaviorSubject < any[] > = new BehaviorSubject < any[] > ([]); // formName,alias,uuid
private headers: Headers = new Headers();
private baseUrl: string = ''
private baseUrl= '';
private formEditorLoaded: BehaviorSubject < boolean > = new BehaviorSubject(false);
private credentials: string;

constructor(private http: Http, private fsc: FormSchemaCompiler, private router: Router, private ns: NavigatorService,
private sessionStorageService: SessionStorageService,private auth:AuthenticationService) {
constructor(private http: Http, private fsc: FormSchemaCompiler, private router: Router, private ns: NavigatorService,
private sessionStorageService: SessionStorageService ,private auth: AuthenticationService) {
this.credentials = sessionStorageService.getItem(Constants.CREDENTIALS_KEY);
auth.getBaseUrl().subscribe((baseUrl) => this.baseUrl = baseUrl);
console.warn(this.baseUrl,"BASE URL");
this.headers.append("Authorization", "Basic " + this.credentials);
console.warn(this.baseUrl, 'BASE URL');
this.headers.append('Authorization', 'Basic ' + this.credentials);
// this.headers.append( 'Content-Type', 'application/json');
}



public fetchFormMetadata(uuid: string, isComponent: boolean) {
return this.http.get(`${this.baseUrl}/ws/rest/v1/form/${uuid}?v=full`, {headers: this.headers})
.map(metadata => {return metadata.json(); })
.map(metadata => metadata.json() )
.catch(error => {
console.log("Error:" + error)
console.log('Error:' + error);
return error;
})
.toPromise()
.toPromise();
}

public fetchForm(valueReference: string, isReferenceForm: boolean) {
let arr;
return this.http.get(`${this.baseUrl}/ws/rest/v1/clobdata/${valueReference}`, {
headers: this.headers
})
Expand All @@ -57,18 +56,16 @@ export class FetchFormDetailService {
this._rawSchema = res.json();
}

if (res.json().referencedForms&&!isReferenceForm) {
if (res.json().referencedForms && !isReferenceForm) {

this.setReferencedFormsDetails(res.json().referencedForms);
return this.fetchReferencedFormSchemas(res.json().referencedForms).then(referencedForms => {
console.log("setting ref forms")
console.log('setting ref forms');
this.referencedFormsSchemasSubject = new BehaviorSubject(referencedForms);
return this.fsc.compileFormSchema(res.json(), referencedForms);
});

}

else {
} else {
return res.json();
}

Expand All @@ -82,20 +79,20 @@ export class FetchFormDetailService {



fetchReferencedFormSchemas(referencedForms: any[]):Promise<any> {
let apiCalls = [];
fetchReferencedFormSchemas(referencedForms: any[]): Promise<any> {
const apiCalls = [];
referencedForms.forEach(form => {
apiCalls.push(this.fetchFormMetadata(form.ref.uuid, true).then(res => this.fetchForm(res.resources[0].valueReference, true)))
apiCalls.push(this.fetchFormMetadata(form.ref.uuid, true).then(res => this.fetchForm(res.resources[0].valueReference, true)));
});
return Promise.all(apiCalls)
return Promise.all(apiCalls);
}

get rawSchema() {
return this._rawSchema;
}

setReferencedFormsSchemasArray(array: any[]) {
this.referencedFormsSchemasSubject.next(array)
this.referencedFormsSchemasSubject.next(array);
}


Expand All @@ -108,9 +105,9 @@ export class FetchFormDetailService {

}

setReferencedFormsDetails(formDits) {
//formName,alias,uuid
this.referencedFormsDetailsSubject.next(formDits)
setReferencedFormsDetails(formDits) {
// formName,alias,uuid
this.referencedFormsDetailsSubject.next(formDits);
}

setLoaded(bool: boolean) {
Expand All @@ -121,14 +118,13 @@ export class FetchFormDetailService {
return this.formEditorLoaded.asObservable();
}

restoreReferencedForms(schema){
restoreReferencedForms(schema) {
if (schema.referencedForms) {
this.setReferencedFormsDetails(schema.referencedForms);
return this.fetchReferencedFormSchemas(schema.referencedForms).then(referencedForms => {
this.referencedFormsSchemasSubject = new BehaviorSubject(referencedForms)
this.referencedFormsSchemasSubject = new BehaviorSubject(referencedForms);
});

}
}
}

}
Expand Down
22 changes: 16 additions & 6 deletions src/app/Services/save-form.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,32 +125,42 @@ export class SaveFormService {

///////////////////////////////////////////////////////////////////////

publish(uuid){
let body = { published : true };
publish(uuid) {
const body = { published : true };
return this.http.post(`${this.baseUrl}/ws/rest/v1/form/${uuid}`,body,{headers:this.headers}).map(res => res.json());
}

unpublish(uuid){
let body = { published : false};
const body = { published : false};
return this.http.post(`${this.baseUrl}/ws/rest/v1/form/${uuid}`,body,{headers:this.headers}).map(res => res.json());
}

updateName(name:string,uuid){
let body = { name : name };
const body = { name : name };
this.setNewFormName(name);
return this.http.post(`${this.baseUrl}/ws/rest/v1/form/${uuid}`,body,{headers:this.headers}).map(res => res.json());
}

updateVersion(version:string,uuid){
let body = { version : version };
const body = { version : version };
this.setNewVersion(version);
return this.http.post(`${this.baseUrl}/ws/rest/v1/form/${uuid}`,body,{headers:this.headers}).map(res => res.json());
}

updateDescription(description:string,uuid){
let body = { description : description };
const body = { description : description };
this.setNewDescription(description);
return this.http.post(`${this.baseUrl}/ws/rest/v1/form/${uuid}`,body,{headers:this.headers}).map(res => res.json());
}

retire(uuid: string) {
// const body = { retired : true, retiredReason : "Retire Reason!" };
return this.http.delete(`${this.baseUrl}/ws/rest/v1/form/${uuid}?!purge`, {headers: this.headers}).map(res => res.json());
}

unretire(uuid: string) {
const body = { retired : false };
return this.http.post(`${this.baseUrl}/ws/rest/v1/form/${uuid}`, body, {headers: this.headers}).map(res => res.json());
}

}
6 changes: 3 additions & 3 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ import { UpdateFormsWizardComponent } from './modals/update-forms-wizard-modal/u
Str2Num,
SetMembersModalComponent,
SnackbarComponent,
BuildVersionFooterComponent,
SaveSnackbarComponent,
BuildVersionFooterComponent,
SaveSnackbarComponent,
FormBuilderComponent,
UpdateFormsWizardComponent,
NotificationComponent
Expand All @@ -83,7 +83,7 @@ import { UpdateFormsWizardComponent } from './modals/update-forms-wizard-modal/u
PromptComponent,
AnswersComponent,
ConceptsModalComponent,
ReferenceModalComponent,
ReferenceModalComponent,
NavigatorModalComponent,
InsertReferenceComponent,
SchemaModalComponent,
Expand Down
Loading