<commit_before>/* jshint indent: false */ // TODO: ENYO-3311

/* global Phonegap */

/**
 * UI: Phonegap pane in the ProjectProperties popup
 * @name Phonegap.BuildStatusUI
 */
enyo.kind({
	name: "Phonegap.ProjectProperties.PlatformBuildStatus",
	kind: "onyx.IconButton",	
	ontap: "showStatusMessage",	
	published: {
		platform: null,
		status: null
	},

	/**
	 * Update the image for the platform IconButton depending on the status of the related platform
	 * described in buildStatusData.
	 * 
	 * @private
	 */
	statusChanged: function() {

		if (this.status === "complete") {
					
			this.setSrc("$services/assets/images/platforms/" + this.platform + "-logo-complete-32x32.png");
			return ; 
		}

		if (this.status === "error"){
			this.show();
			this.setSrc("$services/assets/images/platforms/" + this.platform + "-logo-error-32x32.png");
			return ;
		}
		
		this.setSrc("$services/assets/images/platforms/" + this.platform + "-logo-not-available-32x32.png");
		
	}
});

/**
 * The widget "Build status", show the building state of the application
 * for each platform.  
 */
enyo.kind({
	name: "Phonegap.ProjectProperties.BuildStatus",
	kind: "FittableRows",
	buildStatusData: {},
	published: {
		appId: "",		
		phongapUrl: "https://build.phonegap.com",
		provider: {}, 
		selectedPlatform: null
	},
	events: {
		onError: ""
	},
	handlers: {
		onUpdateStatusMessage: "updateDownloadMessageContent"
	}, 
	components: [
		{
			name: "buildStatusContainer", kind: "FittableRows", classes: "ares-project-properties-build-status-container",
			components: [
				{	
					name: "platformIconContainer",
					classes:"ares-project-properties-platform-icon-container",
					kind: "FittableColumns",					
				},				

				{ name: "downloadStatus", kind: "Phonegap.ProjectProperties.DownloadStatus" },
				{
					name: "messageContainer",
					classes: "ares-project-properties-status-message-container",
					showing: false,
					components: [
						{
							name: "hideStatusContainer",
							kind: "onyx.IconButton",
							src: "$project-view/assets/images/close-button-16x16.png",
							classes: "ares-project-properties-hide-status-button",
							ontap:"hideMessageContainer"
						},				
						{
							name: "statusMessage",
							classes: "ares-project-properties-status-message"
						}
					]
				},
				{
					kind: "FittableColumns",
					style: "height: 32px; position: relative; top:-6em;",
					components: [
						{
							name:"separatorForDownloadButton"
						},
						{
							name: "downloadButton",
							kind: "onyx.IconButton",
							src: "$services/assets/images/download-icon.png",
							showing: false,
							ontap: "downloadPackage"
						}
					]
				}
									
			]
		}
	],
	/**@private*/
	create: function() {
		this.inherited(arguments);
		this.createIconButtons();
		this.appIdChanged();
		this.setProvider(Phonegap.ProjectProperties.getProvider());
	},

	/**
	 * Create the IconButtons displaying the build state of the application
	 * for all platforms defined in the object {Phonegap.ProjectProperties.downloadStatus}
	 * 
	 * @private
	 */
	createIconButtons: function() {
		for (var key in Phonegap.ProjectProperties.downloadStatus) {
			this.$.platformIconContainer.createComponent(
				{
					name: key + "Decorator", 
					classes: "ares-project-properties-build-status-icon",
					components: [						
						{
							name: key + "Button", 
							kind: "Phonegap.ProjectProperties.PlatformBuildStatus", 
							platform: key
						}
					]
				}, 
				{owner: this}
			);			
		}
	},

	/**
	 * Charge the icon showing the build status of the application of a a given platform depending on 
	 * its status. the status is checked from the "buildStatusData" object.
	 * By clicking on the icon, the status message is displayed.
	 * 
	 * @private	 
	 */
	updateBuildStatusData: function(inBuildStatus){
		this.buildStatusData = inBuildStatus;
		var pendingApplication = false;
		
		//Check if there is a pending build.
		for(var key1 in this.buildStatusData && this.buildStatusData.status) {
			if (this.buildStatusData.status[key1] === "pending") {
				pendingApplication = true;
			}
		}

		//If there is a pending build, another buildStatus Request is sent after 600 ms timeout.
		if (pendingApplication) {
			enyo.job("updateBuildStatus", function() {
				this.sendBuildStatusRequest(); 
			}.bind(this), 3000);			
		}

		// Get only the Enyo control that have the "platform" attribute 
		// => {Phonegap.ProjectProperties.PlatformBuildStatus} instance
		for(var key2 in this.$){

			var platform = this.$[key2].platform;
			var status = this.buildStatusData && this.buildStatusData.status[platform];
			
			if (platform !== undefined) {
				this.log("status: ", status, " platform: ", platform)
				this.$[key2].setStatus(status || "notAvailable");
			}
		}

		//Update to Status container if a platform is selected.
		if(this.selectedPlatform !== null) {
			this.showStatusMessage({platform: this.selectedPlatform});
		}
	},

	/**
	 * Use the phonegap service to request a {buildStatus} object from Phonegap build
	 * @private
	 */
	sendBuildStatusRequest: function() {
		<commit_msg>ENYO-2788: remove a log instruction.<commit_after>/* jshint indent: false */ // TODO: ENYO-3311

/* global Phonegap */

/**
 * UI: Phonegap pane in the ProjectProperties popup
 * @name Phonegap.BuildStatusUI
 */
enyo.kind({
	name: "Phonegap.ProjectProperties.PlatformBuildStatus",
	kind: "onyx.IconButton",	
	ontap: "showStatusMessage",	
	published: {
		platform: null,
		status: null
	},

	/**
	 * Update the image for the platform IconButton depending on the status of the related platform
	 * described in buildStatusData.
	 * 
	 * @private
	 */
	statusChanged: function() {

		if (this.status === "complete") {
					
			this.setSrc("$services/assets/images/platforms/" + this.platform + "-logo-complete-32x32.png");
			return ; 
		}

		if (this.status === "error"){
			this.show();
			this.setSrc("$services/assets/images/platforms/" + this.platform + "-logo-error-32x32.png");
			return ;
		}
		
		this.setSrc("$services/assets/images/platforms/" + this.platform + "-logo-not-available-32x32.png");
		
	}
});

/**
 * The widget "Build status", show the building state of the application
 * for each platform.  
 */
enyo.kind({
	name: "Phonegap.ProjectProperties.BuildStatus",
	kind: "FittableRows",
	buildStatusData: {},
	published: {
		appId: "",		
		phongapUrl: "https://build.phonegap.com",
		provider: {}, 
		selectedPlatform: null
	},
	events: {
		onError: ""
	},
	handlers: {
		onUpdateStatusMessage: "updateDownloadMessageContent"
	}, 
	components: [
		{
			name: "buildStatusContainer", kind: "FittableRows", classes: "ares-project-properties-build-status-container",
			components: [
				{	
					name: "platformIconContainer",
					classes:"ares-project-properties-platform-icon-container",
					kind: "FittableColumns",					
				},				

				{ name: "downloadStatus", kind: "Phonegap.ProjectProperties.DownloadStatus" },
				{
					name: "messageContainer",
					classes: "ares-project-properties-status-message-container",
					showing: false,
					components: [
						{
							name: "hideStatusContainer",
							kind: "onyx.IconButton",
							src: "$project-view/assets/images/close-button-16x16.png",
							classes: "ares-project-properties-hide-status-button",
							ontap:"hideMessageContainer"
						},				
						{
							name: "statusMessage",
							classes: "ares-project-properties-status-message"
						}
					]
				},
				{
					kind: "FittableColumns",
					style: "height: 32px; position: relative; top:-6em;",
					components: [
						{
							name:"separatorForDownloadButton"
						},
						{
							name: "downloadButton",
							kind: "onyx.IconButton",
							src: "$services/assets/images/download-icon.png",
							showing: false,
							ontap: "downloadPackage"
						}
					]
				}
									
			]
		}
	],
	/**@private*/
	create: function() {
		this.inherited(arguments);
		this.createIconButtons();
		this.appIdChanged();
		this.setProvider(Phonegap.ProjectProperties.getProvider());
	},

	/**
	 * Create the IconButtons displaying the build state of the application
	 * for all platforms defined in the object {Phonegap.ProjectProperties.downloadStatus}
	 * 
	 * @private
	 */
	createIconButtons: function() {
		for (var key in Phonegap.ProjectProperties.downloadStatus) {
			this.$.platformIconContainer.createComponent(
				{
					name: key + "Decorator", 
					classes: "ares-project-properties-build-status-icon",
					components: [						
						{
							name: key + "Button", 
							kind: "Phonegap.ProjectProperties.PlatformBuildStatus", 
							platform: key
						}
					]
				}, 
				{owner: this}
			);			
		}
	},

	/**
	 * Charge the icon showing the build status of the application of a a given platform depending on 
	 * its status. the status is checked from the "buildStatusData" object.
	 * By clicking on the icon, the status message is displayed.
	 * 
	 * @private	 
	 */
	updateBuildStatusData: function(inBuildStatus){
		this.buildStatusData = inBuildStatus;
		var pendingApplication = false;
		
		//Check if there is a pending build.
		for(var key1 in this.buildStatusData && this.buildStatusData.status) {
			if (this.buildStatusData.status[key1] === "pending") {
				pendingApplication = true;
			}
		}

		//If there is a pending build, another buildStatus Request is sent after 600 ms timeout.
		if (pendingApplication) {
			enyo.job("updateBuildStatus", function() {
				this.sendBuildStatusRequest(); 
			}.bind(this), 3000);			
		}

		// Get only the Enyo control that have the "platform" attribute 
		// => {Phonegap.ProjectProperties.PlatformBuildStatus} instance
		for(var key2 in this.$){

			var platform = this.$[key2].platform;
			var status = this.buildStatusData && this.buildStatusData.status[platform];
			
			if (platform !== undefined) {
				this.$[key2].setStatus(status || "notAvailable");
			}
		}

		//Update to Status container if a platform is selected.
		if(this.selectedPlatform !== null) {
			this.showStatusMessage({platform: this.selectedPlatform});
		}
	},

	/**
	 * Use the phonegap service to request a {buildStatus} object from Phonegap build
	 * @private
	 */
	sendBuildStatusRequest: function() {
		
{'fraction_non_alphanumeric': 0.13261018274210887, 'fraction_numerical': 0.007231505912244698, 'mean_word_length': 3.0789159027501, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7046932', 'n_tokens_mistral': 3951, 'n_tokens_neox': 3056, 'n_words': 700}