<commit_before><%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib prefix="stripes" uri="http://stripes.sourceforge.net/stripes.tld" %>
<stripes:layout-render name="../../../../client/layout/adminlayout.jsp">
	<stripes:layout-component name="contents">

		<script src="scripts/component/visualSearch.js?v=${appVersion}" type="text/javascript"></script>	
		<script src="scripts/plugin/cellToCellDragDrop.js?v=${appVersion}" type="text/javascript"></script>	
		
		<script type="text/javascript">
			/* global Ext, CoreUtil */
			Ext.onReady(function(){	
				
				var visualPanel = Ext.create('OSF.component.VisualSearchPanel', {
					id: 'visualPanel',
					height: '100%',
					viewType: null
				});


				var actionCreateRelationship = function actionCreateRelationship(originId, originName, targetId, targetName, relationshipTypeCode) {

					if (relationshipTypeCode !== null) {
						// Create the relationship as specified
					} else {
						// Prompt for type of relationship to create
						relationshipTypeCode="CON";
					}

					var url = '../api/v1/resource/components/' + originId + '/relationships';
					var method = 'POST';
					var jsonData = {
						relationshipType: relationshipTypeCode,
						relatedComponentId: targetId
					};

					Ext.Ajax.request({
						url: url,
						method: method,
						jsonData: jsonData,
						success: function (response, opts) {
							var message = 'Sucessfully created relationship for "' + originName + '"';
							Ext.toast(message, '', 'tr');
							Ext.getCmp('relationshipsGrid').getStore().load();
						},
						failure: function (response, opts) {
							Ext.MessageBox.alert('Failed to create relationship for "' + originName + '"');
						}
					});
				};

			
				var relationshipsStore = Ext.create('Ext.data.Store', {
					storeId: 'relationshipsStore',
					listeners: {
						load: function() {
							var viewData = [];
								relationshipsStore.each(function(relationship){
									viewData.push({
										type: 'component',
										nodeId: relationship.get('relationshipId'),
										key: relationship.get('ownerComponentId'),
										label: relationship.get('ownerComponentName'),
										relationshipLabel: relationship.get('relationshipTypeDescription'),
										targetKey: relationship.get('targetComponentId'),
										targetName: relationship.get('targetComponentName'),
										targetType: 'component'
									});
								});
								var visPanel = Ext.getCmp('visualPanel');
								visPanel.viewType = null;
								visPanel.reset();
								visPanel.viewData = viewData;
								visPanel.initVisual(visPanel.viewData);
						}
					}
				});

				var relationshipTypeStore = Ext.create('Ext.data.Store', {
					storeId: 'relationshipTypeStore',
					proxy: {
						type: 'ajax',
						url: '../api/v1/resource/lookuptypes/RelationshipType/view'
					},
					autoLoad: true
				});
													   

				var componentsStore = Ext.create('Ext.data.Store', {
					storeId: 'componentsStore',
					fields: [
						// The griddragdrop plugin needs a type in order to operate!
						{
							name: 'description',
							type: 'string'
						}
					],
					sorters: new Ext.util.Sorter({
						property: 'description',
						direction: 'ASC'
					}),
					proxy: {
						id: 'componentsStoreProxy',
						type: 'ajax',
						url: '../api/v1/resource/components/lookup'
					},
					autoLoad: true
				}); 

				var originGrid = Ext.create('Ext.grid.Panel', {
					id: 'originGrid',
					store: componentsStore,
					flex: 1,
					border: true,
					autoScroll: true,
					viewConfig: {
						plugins: {
							ddGroup: 'relationship',
							ptype: 'celltocelldragdrop',
							enableDrop: false,
						}
					},
					columns: [
						{ text: 'Origin Entry', dataIndex: 'description', flex: 1 }
					],
					listeners: {
						select: function(grid, record, index, eOpts) {<commit_msg>Prompt for type of relationship if not set<commit_after><%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib prefix="stripes" uri="http://stripes.sourceforge.net/stripes.tld" %>
<stripes:layout-render name="../../../../client/layout/adminlayout.jsp">
	<stripes:layout-component name="contents">

		<script src="scripts/component/visualSearch.js?v=${appVersion}" type="text/javascript"></script>	
		<script src="scripts/plugin/cellToCellDragDrop.js?v=${appVersion}" type="text/javascript"></script>	
		
		<script type="text/javascript">
			/* global Ext, CoreUtil */
			Ext.onReady(function(){	
				
				var visualPanel = Ext.create('OSF.component.VisualSearchPanel', {
					id: 'visualPanel',
					height: '100%',
					viewType: null
				});


				var actionCreateRelationship = function actionCreateRelationship(originId, originName, targetId, targetName, relationshipTypeCode) {

					if (relationshipTypeCode !== null) {
						// Create the relationship as specified
						var url = '../api/v1/resource/components/' + originId + '/relationships';
						var method = 'POST';
						var jsonData = {
							relationshipType: relationshipTypeCode,
							relatedComponentId: targetId
						};

						Ext.Ajax.request({
							url: url,
							method: method,
							jsonData: jsonData,
							success: function (response, opts) {
								var message = 'Sucessfully created relationship for "' + originName + '"';
								Ext.toast(message, '', 'tr');
								Ext.getCmp('relationshipsGrid').getStore().load();
							},
							failure: function (response, opts) {
								Ext.MessageBox.alert('Failed to create relationship for "' + originName + '"');
							}
						});

					} else {
						// Prompt for type of relationship to create
						typePromptWindow.originId = originId;
						typePromptWindow.originName = originName;
						typePromptWindow.targetId = targetId;
						typePromptWindow.targetName = targetName;
						typePromptWindow.show();
					}

				};
				
			
				var relationshipsStore = Ext.create('Ext.data.Store', {
					storeId: 'relationshipsStore',
					listeners: {
						load: function() {
							var viewData = [];
								relationshipsStore.each(function(relationship){
									viewData.push({
										type: 'component',
										nodeId: relationship.get('relationshipId'),
										key: relationship.get('ownerComponentId'),
										label: relationship.get('ownerComponentName'),
										relationshipLabel: relationship.get('relationshipTypeDescription'),
										targetKey: relationship.get('targetComponentId'),
										targetName: relationship.get('targetComponentName'),
										targetType: 'component'
									});
								});
								var visPanel = Ext.getCmp('visualPanel');
								visPanel.viewType = null;
								visPanel.reset();
								visPanel.viewData = viewData;
								visPanel.initVisual(visPanel.viewData);
						}
					}
				});

				var relationshipTypeStore = Ext.create('Ext.data.Store', {
					storeId: 'relationshipTypeStore',
					proxy: {
						type: 'ajax',
						url: '../api/v1/resource/lookuptypes/RelationshipType/view'
					},
					autoLoad: true
				});
													   

				var componentsStore = Ext.create('Ext.data.Store', {
					storeId: 'componentsStore',
					fields: [
						// The griddragdrop plugin needs a type in order to operate!
						{
							name: 'description',
							type: 'string'
						}
					],
					sorters: new Ext.util.Sorter({
						property: 'description',
						direction: 'ASC'
					}),
					proxy: {
						id: 'componentsStoreProxy',
						type: 'ajax',
						url: '../api/v1/resource/components/lookup'
					},
					autoLoad: true
				}); 
				
				var typePromptWindow = Ext.create('Ext.window.Window', {
					id: 'typePromptWindow',
					title: 'Choose Relationship Type',
					modal: true,
					width: '35%',
					y: '10em',
					layout: 'fit',
					items: [
						{
							xtype: 'combobox',
							id: 'relationshipWindowSelector',
							style: 'padding: 20px;',
							displayField: 'description',
							valueField: 'code',
							width: '100%',
							emptyText: 'Select a relationship type',
							store: relationshipTypeStore,
						}
					],
					dockedItems: [
						{
							xtype: 'toolbar',
							dock: 'bottom',
							items: [
								{
									text: 'Cancel',
									handler: function() {
										this.up('window').hide();
									}
								},
								{
									xtype: 'tbfill',
								},
								{
									text: 'Create Relationship',
									handler: function() {
										var originId = typePromptWindow.originId;
										var originName = typePromptWindow.originName;
										var targetName = typePromptWindow.targetName;
										var targetId = typePromptWindow.targetId;
										var record = Ext.getCmp('relationshipWindowSelector').getSelection();
										var relationshipTypeCode = record.get('code');
										var url = '../api/v1/resource/components/' + originId + '/relationships';
										var method = 'POST';
										var jsonData = {
											relationshipType: relationshipTypeCode,
											relatedComponentId: targetId
										};

										Ext.Ajax.request({
											url: url,
											method: method,
											jsonData: jsonData,
											success: function (response, opts) {
												var message = 'Sucessfully created relationship for "' + originName + '"';
												Ext.toast(message, '', 'tr');
												Ext.getCmp('relationshipsGrid').getStore().load();
												typePromptWindow.hide();
											},
											failure: function (response, opts) {
												Ext.MessageBox.alert('Failed to create relationship for "' + originName + '"');
												typePromptWindow.hide();
											}
										});
									}
								}
							]
						}
					]
				});


				var originGrid = Ext.create('Ext.grid.Panel', {
					id: 'originGrid',
					store: componentsStore,
					flex: 1,
					border: true,
					autoScroll: true,
					viewConfig: {
						plugins: {
							ddGroup: 'relationship',
							ptype: 'celltocelldragdrop',
							enableDrop: false,
						}
					},
					columns: [
						{ text: 'Origin Entry', dataIndex: 'description', flex: 1 }
					],
					listeners: {
						select: function(grid, record, index, eOpts) {
{'fraction_non_alphanumeric': 0.1351084812623274, 'fraction_numerical': 0.0027613412228796844, 'mean_word_length': 2.346864686468647, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '23545', 'n_tokens_mistral': 4542, 'n_tokens_neox': 2836, 'n_words': 578}