{"size": 2269, "ext": "js", "max_stars_repo_path": "disa_app/static/js/editor/editor.source.js", "max_stars_repo_name": "birkin/disa_dj_2019v1_project", "max_stars_repo_stars_event_min_datetime": "2020-07-22T07:28:04.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-22T07:28:04.000Z", "max_issues_repo_path": "disa_app/static/js/editor/editor.source.js", "max_issues_repo_name": "birkin/disa_dj_2019v1_project", "max_issues_repo_issues_event_min_datetime": "2020-06-03T15:28:14.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-17T15:00:19.000Z", "max_forks_repo_path": "disa_app/static/js/editor/editor.source.js", "max_forks_repo_name": "birkin/disa_dj_project", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": 85, "max_forks_count": null, "avg_line_length": 28.012345679, "max_line_length": 151, "alphanum_fraction": 0.5998237109}
class DISASource {

  constructor(baseURL) {
    this._base = baseURL;
    this._apps = {};
    this._base = base_url_segment;  // `base_url_segment` prepared in '/record/relationships/<recId>' and passed to base.html <script/> header-element.
    console.log( "in DISASource constructor(); this._base, ```" + this._base + "```" );
  }

  registerApp( name, app ) {
    this._apps[name] = app;
  }

  getREST( endpoint, callback ) {
    console.log( "in getREST(); endpoint, ```" + endpoint + "```" );
    $.ajax({
      type: "GET",
      dataType: "json",
      url: endpoint,
      success: function( data ) {
        callback( data );
      }
    });
  }

  postREST( endpoint, payload, callback ) {
    $.ajax({
      type: "POST",
      data: JSON.stringify(payload),
      contentType: "application/json",
      dataType: "json",
      url: endpoint,
      success: function( data ) {
        callback( data );
      }
    });
    console.log( "postREST() success complete" );
  }

  delREST( endpoint, payload, callback ) {
    $.ajax({
      type: "DELETE",
      data: JSON.stringify(payload),
      contentType: "application/json",
      dataType: "json",
      url: endpoint,
      success: function( data ) {
        callback( data );
      }
    });
  }

  getRelationships(sectionId) {
    console.log( "in getRelationships(); this._base, ```" + this._base + "```" );
    let endpoint = this._base + `/data/sections/${sectionId}/relationships/`;
    let callback = this._apps['rel-mgmt'].setUp;
    this.getREST(endpoint, callback);
  }

  addRelationship(obj) {
    let endpoint = this._base + `/data/relationships/`;
    console.log( "endpoint: ", endpoint );
    let callback = this._apps['rel-mgmt'].setUp;
    console.log( "callback: ", callback );
    this.postREST(endpoint, obj, callback);
    console.log( "postREST() complete" )
  }

  deleteRelationship(sectionId, relId) {
    let endpoint = this._base + `/data/relationships/${relId}`;
    let callback = this._apps['rel-mgmt'].setUp;
    this.delREST(endpoint, { 'section': sectionId }, callback);
  }

  getLocations(sectionId) {
    var endpoint = this._base + `/data/locations/${sectionId}`;
    let callback = this._apps['loc-mgmt'].loadData
    this.getREST(endpoint, callback);
  }
}
