<commit_before>/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

var fairDataPointPost = {};
var project = theProject;

function fairDataPointPostDialog(schema){
    this._schema = cloneDeep(schema); // this is what can be munched on
    this._createDialog();
    this.fairDataPointPost = fairDataPointPost;
    this.fairDataPointPost.baseUri = "http://";
    this._replaceBaseUri(fairDataPointPost.baseUri,true);
};

fairDataPointPostDialog.prototype._createDialog = function() {
    var self = this;
    var frame = DialogSystem.createDialog();
    
    frame.width("500px");
    
    var header = $('<div></div>').addClass("dialog-header").text("POST to Fair Data Point").appendTo(frame);
    var body = $('<div></div>').addClass("dialog-body").appendTo(frame);
    var footer = $('<div></div>').addClass("dialog-footer").appendTo(frame);
    
    this._constructFooter(footer);
    this._constructBody(body);
  
    this._level = DialogSystem.showDialog(frame);
    this._body = body;
    this._renderBody(body);
};

fairDataPointPostDialog.prototype._constructBody = function(body) {
    var self = this;
    $('<p>' +
        'The created RDF schema provided can now be uploaded to a Fair Data Point. ' +
    '</p>').appendTo(body);
    
    var html = $('<p class="base-uri-space"><span class="emphasized">Base URI </span> <span bind="baseUriSpan" ></span> <a href="#" bind="editBaseUriLink">edit</a></p>').appendTo(body);
//    var html = $('     <div id="metadata-target" ng-app="metadata.form">' +
//            '<metadata-form></metadata-form>'+
//            '<button id="my-btn">Submit</button>'+
//        '</div>' +
//
//        '<script>' +
//            ' angular.bootstrap($("div#metadata-target"), ["metadata.form"] );'+
//        '</script>'
//        '<script src="https://code.angularjs.org/1.6.1/angular.min.js"></script>'+
//        '<script src="metadata-form.js"></script>
//        ).appendTo(body);
    
    var elmts = DOM.bind(html);
    this._baseUriSpan = elmts.baseUriSpan;
    this._catalogDiv = $('<div></div>');
    this._datasetDiv = $('<div></div>');
    this._distributionDiv = $('<div></div>');
    this._pushtoFtpDiv = $('<div></div>');
    elmts.baseUriSpan.text(fairDataPointPost.baseUri);
    elmts.editBaseUriLink.click(function(evt){
    	evt.preventDefault();
    	self._editBaseUri($(evt.target));
    });
};

fairDataPointPostDialog.prototype._constructFooter = function(footer) {
    var self = this;
    
    function progressHandlerFunction(event){
        $(".progress").width((event.loaded/event.total) * 100);
    }

    $('<span style="height:4%;background-color:grey; position:absolute;visibility:visible;margin-left: 100px "></span>').addClass("progress").appendTo(footer);
    
    
    $('<button></button>').addClass('button').html("OK").click(function() {
//        self.fairDataPointPost.baseUri = "http://localhost:8084/fdp";
//        self.fairDataPointPost.ftpHost = '127.0.0.1';
//        self.fairDataPointPost.directory = '/home/citroen';
//        self.fairDataPointPost.username = 'citroen';
//        self.fairDataPointPost.password = "";
//        self.fairDataPointPost.catalog = {_identifier:"test",_title:"test",_version:"test",_theme:"http://test.nl",_publisher:"test"};
//        self.fairDataPointPost.dataset = {_identifier:"test",_title:"test",_publisher:'test',_theme:"http://test.nl",_version:"test"};
//        self.fairDataPointPost.distribution = {_identifier:"test",_title:"test",_version:"test",_accessUrl:"http://test.nl"};
//
       var rdf = '';
        $.ajax({
            type: "POST",
            url : "command/rdf-extension/get-project-rdf",
            data: {project: theProject.id},
            dataTYpe:"json",
            async: false,
            success : function(text)
            {
                rdf = text.data;
            }
        });
        var fairdatapoint = self.fairDataPointPost;
        $.ajax({
            type: "POST",
            url :"command/rdf-extension/post-fdp-info",
            data: JSON.stringify(fairdatapoint)+"#%SPLITHERE%#"+rdf,
            dataType: "json",
            contentType: "application/json",
            xhr: function() {
                var myXhr = $.ajaxSettings.xhr();
                if(myXhr.upload){
                    myXhr.upload.addEventListener('progress',progressHandlerFunction, false);
                }
                return myXhr;
            }
       })
    }).appendTo(footer);
    
    
    $('<button></button>').addClass('button').text("Cancel").click(function() {
        DialogSystem.dismissUntil(self._level100 - 1);
    }).appendTo(footer);
};


fairDataPointPostDialog.prototype._editBaseUri = function(src){
	var self = this;
	var menu = MenuSystem.createMenu().width('400px');
	menu.html('<div class="schema-alignment-link-menu-type-search"><input type="text" bind="newBaseUri" size="50"><br/>'+
			'<button class="button" bind="applyButton">Apply</button>' + 
			'<button class="button" bind="cancelButton">Cancel</button></div>'
                );
	MenuSystem.showMenu(menu,function(){});
	MenuSystem.positionMenuLeftRight(menu, src);
	var elmts = DOM.bind(menu);
	elmts.newBaseUri.val(fairDataPointPost.baseUri).focus().select();
	elmts.applyButton.click(function() {
	    var newBaseUri = elmts.newBaseUri.val();
            if(!newBaseUri || !newBaseUri.substring(7)=='http://'){
                alert('Base URI should start with http://');
                return;
            } if(self.fairDataPointPost.baseUri.length > 7){
                self._catalogDiv.html('');
                self._datasetDiv.html('');
                self._distributionDiv.html('');
                self._pushtoFtpDiv.html('');
                self.uri = self._baseUriSpan.text();
                getFairCatalogs(self._baseUriSpan.text(), self);
                return;
            }
            MenuSystem.dismissAll();<commit_msg>Optmized buildability<commit_after>/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

var fairDataPointPost = {};
var project = theProject;

function fairDataPointPostDialog(schema){
    this._schema = cloneDeep(schema); // this is what can be munched on
    this._createDialog();
    this.fairDataPointPost = fairDataPointPost;
    this.fairDataPointPost.baseUri = "http://";
    this._replaceBaseUri(fairDataPointPost.baseUri,true);
};

fairDataPointPostDialog.prototype._createDialog = function() {
    var self = this;
    var frame = DialogSystem.createDialog();
    
    frame.width("500px");
    
    var header = $('<div></div>').addClass("dialog-header").text("POST to Fair Data Point").appendTo(frame);
    var body = $('<div></div>').addClass("dialog-body").appendTo(frame);
    var footer = $('<div></div>').addClass("dialog-footer").appendTo(frame);
    
    this._constructFooter(footer);
    this._constructBody(body);
  
    this._level = DialogSystem.showDialog(frame);
    this._body = body;
    this._renderBody(body);
};

fairDataPointPostDialog.prototype._constructBody = function(body) {
    var self = this;
    $('<p>' +
        'The created RDF schema provided can now be uploaded to a Fair Data Point. ' +
    '</p>').appendTo(body);
    
    var html = $('<p class="base-uri-space"><span class="emphasized">Base URI </span> <span bind="baseUriSpan" ></span> <a href="#" bind="editBaseUriLink">edit</a></p>').appendTo(body);
//    var html = $('     <div id="metadata-target" ng-app="metadata.form">' +
//            '<metadata-form></metadata-form>'+
//            '<button id="my-btn">Submit</button>'+
//        '</div>' +
//
//        '<script>' +
//            ' angular.bootstrap($("div#metadata-target"), ["metadata.form"] );'+
//        '</script>'
//        '<script src="https://code.angularjs.org/1.6.1/angular.min.js"></script>'+
//        '<script src="metadata-form.js"></script>
//        ).appendTo(body);
    
    var elmts = DOM.bind(html);
    this._baseUriSpan = elmts.baseUriSpan;
    this._catalogDiv = $('<div></div>');
    this._datasetDiv = $('<div></div>');
    this._distributionDiv = $('<div></div>');
    this._pushtoFtpDiv = $('<div></div>');
    elmts.baseUriSpan.text(fairDataPointPost.baseUri);
    elmts.editBaseUriLink.click(function(evt){
    	evt.preventDefault();
    	self._editBaseUri($(evt.target));
    });
};

fairDataPointPostDialog.prototype._constructFooter = function(footer) {
    var self = this;
    
    function progressHandlerFunction(event){
        $(".progress").width((event.loaded/event.total) * 100);
    }

    $('<span style="height:4%;background-color:grey; position:absolute;visibility:visible;margin-left: 100px "></span>').addClass("progress").appendTo(footer);
    
    
    $('<button></button>').addClass('button').html("OK").click(function() {
//        self.fairDataPointPost.baseUri = "http://localhost:8084/fdp";
//        self.fairDataPointPost.ftpHost = '127.0.0.1';
//        self.fairDataPointPost.directory = '/home/citroen';
//        self.fairDataPointPost.username = 'citroen';
//        self.fairDataPointPost.password = "";
//        self.fairDataPointPost.catalog = {_identifier:"test",_title:"test",_version:"test",_theme:"http://test.nl",_publisher:"test"};
//        self.fairDataPointPost.dataset = {_identifier:"test",_title:"test",_publisher:'test',_theme:"http://test.nl",_version:"test"};
//        self.fairDataPointPost.distribution = {_identifier:"test",_title:"test",_version:"test",_accessUrl:"http://test.nl"};
//
       var rdf = '';
        $.ajax({
            type: "POST",
            url : "command/rdf-extension/get-project-rdf",
            data: {project: theProject.id},
            dataTYpe:"json",
            async: false,
            success : function(text)
            {
                rdf = text.data;
            }
        });
        var fairdatapoint = self.fairDataPointPost;
        $.ajax({
            type: "POST",
            url :"command/rdf-extension/post-fdp-info",
            data: JSON.stringify(fairdatapoint)+"#%SPLITHERE%#"+rdf,
            dataType: "json",
            contentType: "application/json",
            xhr: function() {
                var myXhr = $.ajaxSettings.xhr();
                if(myXhr.upload){
                    myXhr.upload.addEventListener('progress',progressHandlerFunction, false);
                }
                return myXhr;
            }
       })
    }).appendTo(footer);
    
    
    $('<button></button>').addClass('button').text("Cancel").click(function() {
        DialogSystem.dismissAll();
    }).appendTo(footer);
};


fairDataPointPostDialog.prototype._editBaseUri = function(src){
	var self = this;
	var menu = MenuSystem.createMenu().width('400px');
	menu.html('<div class="schema-alignment-link-menu-type-search"><input type="text" bind="newBaseUri" size="50"><br/>'+
			'<button class="button" bind="applyButton">Apply</button>' + 
			'<button class="button" bind="cancelButton">Cancel</button></div>'
                );
	MenuSystem.showMenu(menu,function(){});
	MenuSystem.positionMenuLeftRight(menu, src);
	var elmts = DOM.bind(menu);
	elmts.newBaseUri.val(fairDataPointPost.baseUri).focus().select();
	elmts.applyButton.click(function() {
	    var newBaseUri = elmts.newBaseUri.val();
            if(!newBaseUri || !newBaseUri.substring(7)=='http://'){
                alert('Base URI should start with http://');
                return;
            } if(self.fairDataPointPost.baseUri.length > 7){
                self._catalogDiv.html('');
                self._datasetDiv.html('');
                self._distributionDiv.html('');
                self._pushtoFtpDiv.html('');
                self.uri = self._baseUriSpan.text();
                getFairCatalogs(self._baseUriSpan.text(), self);
                return;
            }
            MenuSystem.dismissAll();
{'fraction_non_alphanumeric': 0.1757676348547718, 'fraction_numerical': 0.0053112033195020746, 'mean_word_length': 2.7967863894139886, 'pattern_counts': {'":': 0, '<': 103, '<?xml version=': 0, '>': 105, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2368943', 'n_tokens_mistral': 3737, 'n_tokens_neox': 3603, 'n_words': 547}