<commit_before>/**
 * Copyright (c) 2008-2010 The Sakai Foundation
 *
 * Licensed under the Educational Community License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *             http://www.osedu.org/licenses/ECL-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.sakaiproject.profile2.tool.pages;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

import org.apache.log4j.Logger;
import org.apache.wicket.AttributeModifier;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.feedback.FeedbackMessage;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.upload.FileUpload;
import org.apache.wicket.markup.html.form.upload.MultiFileUploadField;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.markup.html.navigation.paging.PagingNavigator;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.markup.repeater.data.GridView;
import org.apache.wicket.markup.repeater.data.IDataProvider;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.model.ResourceModel;
import org.apache.wicket.model.StringResourceModel;
import org.apache.wicket.util.file.Files;
import org.apache.wicket.util.file.Folder;
import org.apache.wicket.util.lang.Bytes;
import org.sakaiproject.profile2.model.GalleryImage;
import org.sakaiproject.profile2.tool.components.ErrorLevelsFeedbackMessageFilter;
import org.sakaiproject.profile2.tool.components.GalleryImageRenderer;
import org.sakaiproject.profile2.tool.components.IconWithClueTip;
import org.sakaiproject.profile2.tool.dataproviders.GalleryImageDataProvider;
import org.sakaiproject.profile2.util.ProfileConstants;
import org.sakaiproject.profile2.util.ProfileUtils;

/**
 * Main gallery component for viewing the current user's picture gallery.
 * 
 * @author d.<EMAIL>
 */
public class MyPictures extends BasePage {

	private static final Logger log = Logger.getLogger(MyPictures.class);

	private List<File> addPictureFiles = new ArrayList<File>();
	private FileListView addPictureListView;
	private Folder addPictureUploadFolder;
	private GridView gridView;
	
	/**
	 * Constructor for current user.
	 */
	public MyPictures() {
		renderMyPictures(0, sakaiProxy.getCurrentUserId());
	}

	/**
	 * Constructor for current user.
	 * 
	 * @param pageToDisplay
	 *            gallery page index used to set the page the user is returned
	 *            to after making a change to the gallery.
	 */
	public MyPictures(int pageToDisplay) {
		renderMyPictures(pageToDisplay, sakaiProxy.getCurrentUserId());
	}

	/**
	 * Does the actual rendering of the page
	 */
	private void renderMyPictures(int pageToDisplay, String userUuid) {

		log.debug("MyPictures()");
		
		disableLink(myPicturesLink);

		configureFeedback();
		createGalleryForm(userUuid, pageToDisplay);
		createAddPictureForm(userUuid);
	}

	private void createAddPictureForm(final String userUuid) {

		addPictureUploadFolder = new Folder(System
				.getProperty("java.io.tmpdir"), "addPicturesUploadFolder");
		addPictureUploadFolder.mkdirs();
		
		//file feedback will be redirected here
        Label fileFeedback = new Label("fileFeedback");
        fileFeedback.setOutputMarkupPlaceholderTag(true);
        add(fileFeedback);
        
		Form addPictureForm = new FileUploadForm("addPictureForm", userUuid, fileFeedback);
		
		addPictureForm.setOutputMarkupId(true);
		add(addPictureForm);
		
		WebMarkupContainer addPictureContainer = new WebMarkupContainer(
				"addPictureContainer");
		addPictureContainer.add(new Label("addPictureLabel", new ResourceModel(
				"pictures.addpicture")));

		addPictureContainer.add(new MultiFileUploadField("choosePicture",
				new PropertyModel<Collection<FileUpload>>(addPictureForm,
						"uploads"), ProfileConstants.MAX_GALLERY_FILE_UPLOADS));

		Button submitButton = new Button("submitPicture", new ResourceModel(
				"button.gallery.upload"));
		addPictureContainer.add(submitButton);

		addPictureContainer
				.add(new IconWithClueTip("galleryImageUploadToolTip",
						ProfileConstants.INFO_IMAGE, new StringResourceModel(
								"text.gallery.upload.tooltip", null,
								new Object[] { sakaiProxy.getMaxProfilePictureSize()
										* ProfileConstants.MAX_GALLERY_FILE_UPLOADS })));
		
		addPictureForm.add(addPictureContainer);
		
		addPictureFiles.addAll(Arrays
				.asList(addPictureUploadFolder.listFiles()));
		addPictureListView = new FileListView("fileList", addPictureFiles);
		addPictureForm.add(addPictureListView);
	}

	private void createGalleryForm(final String userUuid, int pageToDisplay) {

		Label galleryHeading = new Label("galleryHeading", new ResourceModel(
				"heading.pictures.my.pictures"));<commit_msg>PRFL-533: add a busy indicator when uploading gallery images<commit_after>/**
 * Copyright (c) 2008-2010 The Sakai Foundation
 *
 * Licensed under the Educational Community License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *             http://www.osedu.org/licenses/ECL-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.sakaiproject.profile2.tool.pages;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

import org.apache.log4j.Logger;
import org.apache.wicket.AttributeModifier;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.extensions.ajax.markup.html.IndicatingAjaxButton;
import org.apache.wicket.feedback.FeedbackMessage;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.upload.FileUpload;
import org.apache.wicket.markup.html.form.upload.MultiFileUploadField;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.markup.html.navigation.paging.PagingNavigator;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.markup.repeater.data.GridView;
import org.apache.wicket.markup.repeater.data.IDataProvider;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.model.ResourceModel;
import org.apache.wicket.model.StringResourceModel;
import org.apache.wicket.util.file.Files;
import org.apache.wicket.util.file.Folder;
import org.apache.wicket.util.lang.Bytes;
import org.sakaiproject.profile2.model.GalleryImage;
import org.sakaiproject.profile2.tool.components.ErrorLevelsFeedbackMessageFilter;
import org.sakaiproject.profile2.tool.components.GalleryImageRenderer;
import org.sakaiproject.profile2.tool.components.IconWithClueTip;
import org.sakaiproject.profile2.tool.dataproviders.GalleryImageDataProvider;
import org.sakaiproject.profile2.util.ProfileConstants;
import org.sakaiproject.profile2.util.ProfileUtils;

/**
 * Main gallery component for viewing the current user's picture gallery.
 * 
 * @author <EMAIL>
 */
public class MyPictures extends BasePage {

	private static final Logger log = Logger.getLogger(MyPictures.class);

	private List<File> addPictureFiles = new ArrayList<File>();
	private FileListView addPictureListView;
	private Folder addPictureUploadFolder;
	private GridView gridView;
	
	/**
	 * Constructor for current user.
	 */
	public MyPictures() {
		renderMyPictures(0, sakaiProxy.getCurrentUserId());
	}

	/**
	 * Constructor for current user.
	 * 
	 * @param pageToDisplay
	 *            gallery page index used to set the page the user is returned
	 *            to after making a change to the gallery.
	 */
	public MyPictures(int pageToDisplay) {
		renderMyPictures(pageToDisplay, sakaiProxy.getCurrentUserId());
	}

	/**
	 * Does the actual rendering of the page
	 */
	private void renderMyPictures(int pageToDisplay, String userUuid) {

		log.debug("MyPictures()");
		
		disableLink(myPicturesLink);

		configureFeedback();
		createGalleryForm(userUuid, pageToDisplay);
		createAddPictureForm(userUuid);
	}

	private void createAddPictureForm(final String userUuid) {

		addPictureUploadFolder = new Folder(System
				.getProperty("java.io.tmpdir"), "addPicturesUploadFolder");
		addPictureUploadFolder.mkdirs();
		
		//file feedback will be redirected here
        Label fileFeedback = new Label("fileFeedback");
        fileFeedback.setOutputMarkupPlaceholderTag(true);
        add(fileFeedback);
        
		Form addPictureForm = new FileUploadForm("addPictureForm", userUuid, fileFeedback);
		
		addPictureForm.setOutputMarkupId(true);
		add(addPictureForm);
		
		WebMarkupContainer addPictureContainer = new WebMarkupContainer(
				"addPictureContainer");
		addPictureContainer.add(new Label("addPictureLabel", new ResourceModel(
				"pictures.addpicture")));

		addPictureContainer.add(new MultiFileUploadField("choosePicture",
				new PropertyModel<Collection<FileUpload>>(addPictureForm,
						"uploads"), ProfileConstants.MAX_GALLERY_FILE_UPLOADS));

		IndicatingAjaxButton submitButton = new IndicatingAjaxButton(
				"submitPicture", new ResourceModel("button.gallery.upload")) {

			private static final long serialVersionUID = 1L;

			@Override
			protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
			}

		};
		addPictureContainer.add(submitButton);

		addPictureContainer
				.add(new IconWithClueTip("galleryImageUploadToolTip",
						ProfileConstants.INFO_IMAGE, new StringResourceModel(
								"text.gallery.upload.tooltip", null,
								new Object[] { sakaiProxy.getMaxProfilePictureSize()
										* ProfileConstants.MAX_GALLERY_FILE_UPLOADS })));
		
		addPictureForm.add(addPictureContainer);
		
		addPictureFiles.addAll(Arrays
				.asList(addPictureUploadFolder.listFiles()));
		addPictureListView = new FileListView("fileList", addPictureFiles);
		addPictureForm.add(addPictureListView);
	}

	private void createGalleryForm(final String userUuid, int pageToDisplay) {

		Label galleryHeading = new Label("galleryHeading", new ResourceModel(
				"heading.pictures.my.pictures"));
{'fraction_non_alphanumeric': 0.09890013966480447, 'fraction_numerical': 0.004189944134078212, 'mean_word_length': 5.020493956910141, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7592260', 'n_tokens_mistral': 3764, 'n_tokens_neox': 3364, 'n_words': 720}