Skip to content

Commit

Permalink
Add title / description to Queried compartments (Issue #164)
Browse files Browse the repository at this point in the history
  • Loading branch information
toxophilist committed Nov 18, 2020
1 parent 7fd414d commit 2a44ac6
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 10 deletions.
34 changes: 34 additions & 0 deletions okitweb/okitOci.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@
__module__ = "okitOci"
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#

import json
import oci
import os
import shutil
import tempfile
import time
import urllib
from flask import Blueprint
from flask import request
from flask import jsonify

import json
from common.okitCommon import logJson
Expand Down Expand Up @@ -80,6 +83,37 @@
# Define Error Handlers
#

@bp.errorhandler(oci.exceptions.ServiceError)
def handle_oci_service_error(error):
status_code = 500
success = False
message = ''
code = ''
for x in error.args:
logger.info(x)
if 'opc-request-id' in x:
code = x['code']
message = x['message']
status_code = x['status']
break
logger.info(message)
response = {
'success': success,
'error': {
'type': error.__class__.__name__,
'code': code,
'message': message
}
}
logger.exception(error)
logJson(response)
return jsonify(response), status_code


#
# Define Endpoints
#

@bp.route('/resourcemanager', methods=(['GET', 'POST']))
def ociResourceManger():
if request.method == 'GET':
Expand Down
1 change: 1 addition & 0 deletions okitweb/okitWebDesigner.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#

import configparser
import oci
import os
import shutil
import tempfile
Expand Down
8 changes: 0 additions & 8 deletions okitweb/static/okit/js/okit.js
Original file line number Diff line number Diff line change
Expand Up @@ -703,29 +703,21 @@ class OkitAutoSave {
this.stopAutoSave();
this.autoInterval = setInterval(() => {
localStorage.setItem(this.key, JSON.stringify(okitJsonModel));
console.warn('Saved to Local Storage');
console.warn(localStorage.getItem(this.key));
}, timeout);
localStorage.setItem(this.key, JSON.stringify(okitJsonModel));
}

stopAutoSave() {
console.warn('Stop Auto Save');
console.warn(localStorage.getItem(this.key));
this.autoInterval ? clearInterval(this.autoInterval) : this.autoInterval = undefined;
this.removeAutoSave();
}

getOkitJsonModel() {
console.warn('Get Auto Save');
console.warn(localStorage.getItem(this.key));
const okitJson = localStorage.getItem(this.key);
return okitJson ? JSON.parse(okitJson) : undefined;
}

removeAutoSave() {
localStorage.removeItem(this.key);
console.warn('Remove Auto Save');
console.warn(localStorage.getItem(this.key));
}
}
8 changes: 6 additions & 2 deletions okitweb/static/okit/model/js/okit_model.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,12 @@ class OkitJson {
load(okit_json) {
console.log('Load OKIT Json');
// Title & Description
this.title = okit_json.title;
this.description = okit_json.description;
if (okit_json.title) {
this.title = okit_json.title;
}
if (okit_json.description) {
this.description = okit_json.description;
}
// Compartments
if (okit_json.hasOwnProperty('compartments')) {
for (let artefact of okit_json['compartments']) {
Expand Down
11 changes: 11 additions & 0 deletions okitweb/static/okit/query/oci/js/okit_query.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,12 @@ class OkitOCIQuery {
data: JSON.stringify(request),
success: function(resp) {
let response_json = JSON.parse(resp);
let title = request.sub_compartments ? `Queried Compartment ${response_json.name} and Sub-Compartments` : `Queried Compartment ${response_json.name}`;
let description = `${title} in Region ${request.region}`;
response_json.compartment_id = null;
regionOkitJson[request.region].load({compartments: [response_json]})
regionOkitJson[request.region].title = title;
regionOkitJson[request.region].description = description;
let sub_query_request = JSON.clone(request);
sub_query_request.compartment_id = response_json.id;
me.queryCompartmentSubComponents(sub_query_request);
Expand All @@ -125,6 +129,13 @@ class OkitOCIQuery {
console.error('Error : ' + error);
const empty_compartment = {compartment_id: null, display_name: request.compartment_name, name: request.compartment_name};
regionOkitJson[request.region].load({compartments: [empty_compartment]})
regionOkitJson[request.region].title = 'Query Failed';
regionOkitJson[request.region].description = error;
if (error === 'UNAUTHORIZED') {
const response = JSON.parse(xhr.responseText);
console.error(response);
regionOkitJson[request.region].description = `${response.error.code}: ${response.error.message}`;
}
},
complete: function () {
me.region_query_count[request.region]-- && me.isComplete();
Expand Down

0 comments on commit 2a44ac6

Please sign in to comment.