<commit_before>Ext.define('AdmClient.view.mapconfiguration.layer.LayerDetails', {
	extend : 'Ext.window.Window',
	alias : 'widget.layerDetails',

	requires: [
		'Ext.window.Window',
		'Ext.data.XmlStore',
		'GeoExt.data.WfsCapabilitiesLayerStore',
		'GeoExt.data.WmsCapabilitiesLayerStore',
		'GeoExt.data.AttributeStore'
	],
	layout: {
		type : 'border',
		margin : 8
	},
	title : 'Lager inst&auml;llningar',
	width : 600,
	height : 400,
	defaultAlign: 'c',

	constructor : function(){
		this.layer = arguments[0].selectedLayer;
		this.panelGrid = arguments[0].grid;

		if (this.layer === null){
			Ext.Msg.show({
				title: 'Inget lagernamn.',
				msg: 'Kan ej editera grupplager.',
				buttons: Ext.Msg.OK,
				icon: Ext.Msg.WARNING
			});
			this.close();
			return;
		}

		this.title +=  ' - ' + this.layer.name;

		this.callParent(arguments);
	},

	getAttributeCollection: function(attributes){
		var items = [];
		for (var key in attributes){
				var item = [key, '', false];
				items.push(item);
		}
		return items;
	},

	getItem: function(item){
		item.forEach(function(row){
			console.log(row);
		});
	},

	initComponent : function() {

		var self = this;
		this.modal = true;
		
		if (this.layer.wfs){
			var getTypeName = function(layer) {
				if (layer.wfs.featurePrefix && layer.wfs.featureType) {
					return layer.wfs.featurePrefix + ':' + layer.wfs.featureType;
				} else if (layer.name) {
					return layer.name;
				} else {
					Ext.Error.raise({
		                msg: 'No valid layer name for WFS-layer',
		                option: this
		            });
				}
					
			};
			
			var wfsUrl = proxyUrl + (this.layer.wfs.url ? this.layer.wfs.url : wfsServer) + '?service=wfs&request=DescribeFeatureType&version=1.0.0&typeName=' + getTypeName(this.layer);
			this.store = Ext.create('GeoExt.data.AttributeStore');
			var proxy = this.store.getProxy();
//			Ext.apply(proxy.proxyConfig, {headers: {"Content-Type": "application/xml; charset=UTF-8"}});

			this.store.setUrl(wfsUrl);
			this.store.load();
		}
		else if (this.layer.wms){
			var pathArray = this.layer.wms.url.split('/');

			this.store = Ext.create('Ext.data.ArrayStore', {fields: [
				{name: 'name'},
                {name: 'alias'},
                {name: 'visible', type: 'boolean', defaultValue: true},
                {name: 'mainAttribute', type:'boolean', defaultValue: false}
                ]
            });

			this.wmsStore = Ext.create('GeoExt.data.WmsCapabilitiesLayerStore',{
				url: wmsGetCapabilities
			});

			
			
			this.wmsStore.load({
                scope: this,
                callback: function(records, operation, success) {
        			var getLayerName = function(layer) {
        				if (layer.wms.params && layer.wms.params.LAYERS) {
        					return layer.wms.params.LAYERS;
        				} else if (layer.name) {
        					return layer.name;
        				} else {
        					Ext.Error.raise({
        		                msg: 'No valid layer name for WMS-layer',
        		                option: this
        		            });
        					return undefined;
        				}
        			};
                	var layerName = getLayerName(this.layer);
                    if(layerName && records && records.length > 0) {
                    	records = records.filter(function(record){
                    		return record.get('name') === layerName;
                    	});
                        
                        if (records.length > 0) {
	                        records.forEach(function(record) {
                            	var boundaryBox = record.get('bbox');
								var success = function(){
									if (arguments[0].responseXML) {
										var format = new OpenLayers.Format.GML();
										var feature = format.read(arguments[0].responseXML);
										var fields = this.getAttributeCollection(feature[0].attributes);
										
	
										if (this.layer.metadata && this.layer.metadata.attributes && this.layer.metadata.attributes instanceof Object) {
											var attributesInLayer = this.layer.metadata.attributes;
											var fieldsFilter = function(f){
												return f[0] === attribute;
											};
											for (var attribute in attributesInLayer){
												var item = fields.filter(fieldsFilter, f);
												if (item.length > 0) {
													item[0][1] = item[0][1] === '' ? attributesInLayer[attribute].alias : item[0][1];
													item[0][2] = true;
												}
											}
										}
										this.store.loadData(fields);
									} else {
										this.close();
										Ext.Error.raise({
											title: 'Kommunikationsproblem',
											msg: 'Kan inte hämta information om lagret'
										});
									}
								};

                            	for (var srsName in boundaryBox){
                            		var boundary = boundaryBox[srsName].bbox;
                            		var extent = new OpenLayers.Bounds.fromArray(boundary);

                            		var requestUrl = proxyUrl + wmsServer + '?' + 'request=GetFeatureInfo&service=WMS&version=1.1.1&layers=' + layerName + '&styles=&srs=' + srsName + '&bbox=' + extent.toString() + 
                            		 	'&width=1&height=1&query_layers=' + layerName + '&info_format=application/vnd.ogc.gml&feature_count=1&x=0&y=0';
                            		Ext.Ajax.request({
                            		 	scope: this,
                            		 	url: requestUrl,
                            		 	success: success
                            		});
                            	}
	                        }, this);
	                    } else {
	                    	Ext.Error.raise({
	                            msg: 'Cant get metadata for layer' + layerName,
	                            option: this
	                        });	            
	                    }
                    } else {
                    	Ext.Error.raise({
                            msg: 'Cant get metadata for layer' + layerName,
                            option: this
                        });	            <commit_msg>Enhanced error handling of attribute settings for WMS-identifiable layers<commit_after>Ext.define('AdmClient.view.mapconfiguration.layer.LayerDetails', {
	extend : 'Ext.window.Window',
	alias : 'widget.layerDetails',

	requires: [
		'Ext.window.Window',
		'Ext.data.XmlStore',
		'GeoExt.data.WfsCapabilitiesLayerStore',
		'GeoExt.data.WmsCapabilitiesLayerStore',
		'GeoExt.data.AttributeStore'
	],
	layout: {
		type : 'border',
		margin : 8
	},
	title : 'Lager inst&auml;llningar',
	width : 600,
	height : 400,
	defaultAlign: 'c',

	constructor : function(){
		this.layer = arguments[0].selectedLayer;
		this.panelGrid = arguments[0].grid;

		if (this.layer === null){
			Ext.Msg.show({
				title: 'Inget lagernamn.',
				msg: 'Kan ej editera grupplager.',
				buttons: Ext.Msg.OK,
				icon: Ext.Msg.WARNING
			});
			this.close();
			return;
		}

		this.title +=  ' - ' + this.layer.name;

		this.callParent(arguments);
	},

	getAttributeCollection: function(attributes){
		var items = [];
		for (var key in attributes){
				var item = [key, '', false];
				items.push(item);
		}
		return items;
	},

	getItem: function(item){
		item.forEach(function(row){
			console.log(row);
		});
	},

	initComponent : function() {

		var self = this;
		this.modal = true;
		
		if (this.layer.wfs){
			var getTypeName = function(layer) {
				if (layer.wfs.featurePrefix && layer.wfs.featureType) {
					return layer.wfs.featurePrefix + ':' + layer.wfs.featureType;
				} else if (layer.name) {
					return layer.name;
				} else {
					Ext.Error.raise({
		                msg: 'No valid layer name for WFS-layer',
		                option: this
		            });
				}
					
			};
			
			var wfsUrl = proxyUrl + (this.layer.wfs.url ? this.layer.wfs.url : wfsServer) + '?service=wfs&request=DescribeFeatureType&version=1.0.0&typeName=' + getTypeName(this.layer);
			this.store = Ext.create('GeoExt.data.AttributeStore');
			var proxy = this.store.getProxy();
//			Ext.apply(proxy.proxyConfig, {headers: {"Content-Type": "application/xml; charset=UTF-8"}});

			this.store.setUrl(wfsUrl);
			this.store.load();
		}
		else if (this.layer.wms){
			var pathArray = this.layer.wms.url.split('/');

			this.store = Ext.create('Ext.data.ArrayStore', {fields: [
				{name: 'name'},
                {name: 'alias'},
                {name: 'visible', type: 'boolean', defaultValue: true},
                {name: 'mainAttribute', type:'boolean', defaultValue: false}
                ]
            });

			this.wmsStore = Ext.create('GeoExt.data.WmsCapabilitiesLayerStore',{
				url: proxyUrl + defaultWMSServer
			});

			
			
			this.wmsStore.load({
                scope: this,
                callback: function(records, operation, success) {
        			var getLayerName = function(layer) {
        				if (layer.wms.params && layer.wms.params.LAYERS) {
        					return layer.wms.params.LAYERS;
        				} else if (layer.name) {
        					return layer.name;
        				} else {
        					Ext.Error.raise({
        		                msg: 'No valid layer name for WMS-layer',
        		                option: this
        		            });
        					return undefined;
        				}
        			};
                	var layerName = getLayerName(this.layer);
                    if(layerName && records && records.length > 0) {
                    	records = records.filter(function(record){
                    		return record.get('name') === layerName;
                    	});
                        
                        if (records.length > 0) {
	                        records.forEach(function(record) {
                            	var boundaryBox = record.get('bbox');
								var success = function(){
									if (arguments[0].responseXML) {
										var format = new OpenLayers.Format.GML();
										var feature = format.read(arguments[0].responseXML);
										if (feature.length > 0) {
											var fields = this.getAttributeCollection(feature[0].attributes);
											
		
											if (this.layer.metadata && this.layer.metadata.attributes && this.layer.metadata.attributes instanceof Object) {
												var attributesInLayer = this.layer.metadata.attributes;
												var fieldsFilter = function(f){
													return f[0] === attribute;
												};
												for (var attribute in attributesInLayer){
													var item = fields.filter(fieldsFilter, f);
													if (item.length > 0) {
														item[0][1] = item[0][1] === '' ? attributesInLayer[attribute].alias : item[0][1];
														item[0][2] = true;
													}
												}
											}
											this.store.loadData(fields);
										} else {
											this.close();
											Ext.Error.raise({
												title: 'Kommunikationsproblem',
												msg: 'Kan inte hämta information om lagret'
											});
										}
									} else {
										this.close();
										Ext.Error.raise({
											title: 'Kommunikationsproblem',
											msg: 'Kan inte hämta information om lagret'
										});
									}
								};

								var requestUrl;
                            	for (var srsName in boundaryBox){
                            		var boundary = boundaryBox[srsName].bbox;
                            		var extent = new OpenLayers.Bounds.fromArray(boundary);
                            		
                            		requestUrl = proxyUrl + (this.layer.wms.url ? this.layer.wms.url : defaultWMSServer) + '?' + 'request=GetFeatureInfo&service=WMS&version=1.1.1&layers=' + layerName + '&styles=&srs=' + srsName + '&bbox=' + extent.toString() + 
                            		 	'&width=1&height=1&query_layers=' + layerName + '&info_format=application/vnd.ogc.gml&feature_count=1&x=0&y=0';
                            		break;
                            	}
                            		Ext.Ajax.request({
                            		 	scope: this,
                            		 	url: requestUrl,
                            		 	success: success
                            		});
//                            	}
	                        }, this);
	                    } else {
							this.close();
	                    	Ext.Error.raise({
	                            msg: 'Cant get metadata for layer' + layerName,
	                            option: this
	                        });	            
	                    }
                    } else {
						this.close();
                    	Ext.Error.raise({
                            msg: 'Cant get metadata for layer' + layerName,
                            option: this
                        });	            
{'fraction_non_alphanumeric': 0.1270129460056836, 'fraction_numerical': 0.00576255131038838, 'mean_word_length': 1.5419341894060996, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '6986814', 'n_tokens_mistral': 4718, 'n_tokens_neox': 3652, 'n_words': 674}