<commit_before>/*
 * Copyright (C) 2010 BloatIt. This file is part of BloatIt. BloatIt is free
 * software: you can redistribute it and/or modify it under the terms of the GNU
 * Affero General Public License as published by the Free Software Foundation,
 * either version 3 of the License, or (at your option) any later version.
 * BloatIt is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
 * details. You should have received a copy of the GNU Affero General Public
 * License along with BloatIt. If not, see <http://www.gnu.org/licenses/>.
 */
package com.bloatit.web.linkable.members;

import static com.bloatit.framework.webprocessor.context.Context.tr;

import java.util.Locale;

import com.bloatit.framework.exceptions.highlevel.ShallNotPassException;
import com.bloatit.framework.exceptions.lowlevel.RedirectException;
import com.bloatit.framework.utils.PageIterable;
import com.bloatit.framework.webprocessor.annotations.NonOptional;
import com.bloatit.framework.webprocessor.annotations.Optional;
import com.bloatit.framework.webprocessor.annotations.ParamContainer;
import com.bloatit.framework.webprocessor.annotations.RequestParam;
import com.bloatit.framework.webprocessor.annotations.RequestParam.Role;
import com.bloatit.framework.webprocessor.annotations.SubParamContainer;
import com.bloatit.framework.webprocessor.annotations.tr;
import com.bloatit.framework.webprocessor.components.HtmlBlockquote;
import com.bloatit.framework.webprocessor.components.HtmlDiv;
import com.bloatit.framework.webprocessor.components.HtmlList;
import com.bloatit.framework.webprocessor.components.HtmlParagraph;
import com.bloatit.framework.webprocessor.components.HtmlSpan;
import com.bloatit.framework.webprocessor.components.HtmlTitleBlock;
import com.bloatit.framework.webprocessor.components.PlaceHolderElement;
import com.bloatit.framework.webprocessor.components.advanced.HtmlTabBlock;
import com.bloatit.framework.webprocessor.components.meta.HtmlBranch;
import com.bloatit.framework.webprocessor.components.meta.HtmlElement;
import com.bloatit.framework.webprocessor.components.renderer.HtmlCachedMarkdownRenderer;
import com.bloatit.framework.webprocessor.context.Context;
import com.bloatit.model.Member;
import com.bloatit.model.Team;
import com.bloatit.model.right.Action;
import com.bloatit.model.right.AuthToken;
import com.bloatit.model.right.UnauthorizedOperationException;
import com.bloatit.web.WebConfiguration;
import com.bloatit.web.components.SideBarButton;
import com.bloatit.web.linkable.documentation.SideBarDocumentationBlock;
import com.bloatit.web.linkable.master.Breadcrumb;
import com.bloatit.web.linkable.master.ElveosPage;
import com.bloatit.web.linkable.master.sidebar.TitleSideBarElementLayout;
import com.bloatit.web.linkable.master.sidebar.TwoColumnLayout;
import com.bloatit.web.linkable.members.tabs.AccountTab;
import com.bloatit.web.linkable.members.tabs.DashboardTab;
import com.bloatit.web.linkable.members.tabs.HistoryTab;
import com.bloatit.web.linkable.members.tabs.InvoicingContactTab;
import com.bloatit.web.linkable.members.tabs.TasksTab;
import com.bloatit.web.linkable.money.SideBarLoadAccountBlock;
import com.bloatit.web.linkable.money.SideBarWithdrawMoneyBlock;
import com.bloatit.web.url.ActivityPageUrl;
import com.bloatit.web.url.MemberPageUrl;
import com.bloatit.web.url.ModifyMemberPageUrl;
import com.bloatit.web.url.TeamPageUrl;

/**
 * <p>
 * A page used to display member information.
 * </p>
 * <p>
 * If the consulted member is the same as the logged member, then this page will
 * propose to edit account parameters
 * </p>
 */
@ParamContainer("members/%member%")
public final class MemberPage extends ElveosPage {
    private final MemberPageUrl url;

    public final static String MEMBER_TAB_PANE = "tab";
    public final static String TASKS_TAB = "tasks";
    public final static String ACTIVITY_TAB = "history";
    public final static String ACCOUNT_TAB = "account";
    public final static String INVOICING_TAB = "invoicing";
    public final static String DASHBOARD_TAB = "dashboard";

    @SubParamContainer
    private HistoryTab history;

    @SubParamContainer
    private DashboardTab dashboard;

    @RequestParam(name = MEMBER_TAB_PANE)
    @Optional(ACTIVITY_TAB)
    private final String activeTabKey;

    @NonOptional(@tr("You have to specify a member number."))
    @RequestParam(role = Role.PAGENAME, message = @tr("I cannot find the member number: ''%value%''."))
    private final Member member;

    public MemberPage(final MemberPageUrl url) {
        super(url);
        this.url = url;
        this.member = url.getMember();
        this.activeTabKey = url.getActiveTabKey();
    }

    @Override
    protected HtmlElement createBodyContent() throws RedirectException {
        final TwoColumnLayout layout = new TwoColumnLayout(false, url);

        boolean myPage;
        if (AuthToken.isAuthenticated() && member != null && member.equals(AuthToken.getMember())) {
            myPage = true;
        } else {
            myPage = false;
        }

        layout.addLeft(generateMemberPageMain(myPage));

        if (member.canGetInternalAccount()) {
            layout.addLeft(generateTabPane());
        }

        // Adding activity page link

        final ActivityPageUrl activityPageUrl = new ActivityPageUrl();
        activityPageUrl.setMember(member);

        if (myPage) {
            layout.addRight(new SideBarButton(Context.tr("My activity"), activityPageUrl, WebConfiguration.getImgActivitySmall(), false));
        } else {
            layout.addRight(new SideBarButton(Context.tr("{0}''s activity", member.getDisplayName()),
                                              activityPageUrl,
                                              WebConfiguration.getImgActivitySmall(),
                                              false));
        }

        // Adding list of teams
        final TitleSideBarElementLayout teamBlock = new TitleSideBarElementLayout();
        try {
            if (myPage) {
                teamBlock.setTitle(Context.tr("My teams"));<commit_msg>hide activity button for member that follow no features<commit_after>/*
 * Copyright (C) 2010 BloatIt. This file is part of BloatIt. BloatIt is free
 * software: you can redistribute it and/or modify it under the terms of the GNU
 * Affero General Public License as published by the Free Software Foundation,
 * either version 3 of the License, or (at your option) any later version.
 * BloatIt is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
 * details. You should have received a copy of the GNU Affero General Public
 * License along with BloatIt. If not, see <http://www.gnu.org/licenses/>.
 */
package com.bloatit.web.linkable.members;

import static com.bloatit.framework.webprocessor.context.Context.tr;

import java.util.Locale;

import com.bloatit.framework.exceptions.highlevel.ShallNotPassException;
import com.bloatit.framework.exceptions.lowlevel.RedirectException;
import com.bloatit.framework.utils.PageIterable;
import com.bloatit.framework.webprocessor.annotations.NonOptional;
import com.bloatit.framework.webprocessor.annotations.Optional;
import com.bloatit.framework.webprocessor.annotations.ParamContainer;
import com.bloatit.framework.webprocessor.annotations.RequestParam;
import com.bloatit.framework.webprocessor.annotations.RequestParam.Role;
import com.bloatit.framework.webprocessor.annotations.SubParamContainer;
import com.bloatit.framework.webprocessor.annotations.tr;
import com.bloatit.framework.webprocessor.components.HtmlBlockquote;
import com.bloatit.framework.webprocessor.components.HtmlDiv;
import com.bloatit.framework.webprocessor.components.HtmlList;
import com.bloatit.framework.webprocessor.components.HtmlParagraph;
import com.bloatit.framework.webprocessor.components.HtmlSpan;
import com.bloatit.framework.webprocessor.components.HtmlTitleBlock;
import com.bloatit.framework.webprocessor.components.PlaceHolderElement;
import com.bloatit.framework.webprocessor.components.advanced.HtmlTabBlock;
import com.bloatit.framework.webprocessor.components.meta.HtmlBranch;
import com.bloatit.framework.webprocessor.components.meta.HtmlElement;
import com.bloatit.framework.webprocessor.components.renderer.HtmlCachedMarkdownRenderer;
import com.bloatit.framework.webprocessor.context.Context;
import com.bloatit.model.Member;
import com.bloatit.model.Team;
import com.bloatit.model.right.Action;
import com.bloatit.model.right.AuthToken;
import com.bloatit.model.right.UnauthorizedOperationException;
import com.bloatit.web.WebConfiguration;
import com.bloatit.web.components.SideBarButton;
import com.bloatit.web.linkable.documentation.SideBarDocumentationBlock;
import com.bloatit.web.linkable.master.Breadcrumb;
import com.bloatit.web.linkable.master.ElveosPage;
import com.bloatit.web.linkable.master.sidebar.TitleSideBarElementLayout;
import com.bloatit.web.linkable.master.sidebar.TwoColumnLayout;
import com.bloatit.web.linkable.members.tabs.AccountTab;
import com.bloatit.web.linkable.members.tabs.DashboardTab;
import com.bloatit.web.linkable.members.tabs.HistoryTab;
import com.bloatit.web.linkable.members.tabs.InvoicingContactTab;
import com.bloatit.web.linkable.members.tabs.TasksTab;
import com.bloatit.web.linkable.money.SideBarLoadAccountBlock;
import com.bloatit.web.linkable.money.SideBarWithdrawMoneyBlock;
import com.bloatit.web.url.ActivityPageUrl;
import com.bloatit.web.url.MemberPageUrl;
import com.bloatit.web.url.ModifyMemberPageUrl;
import com.bloatit.web.url.TeamPageUrl;

/**
 * <p>
 * A page used to display member information.
 * </p>
 * <p>
 * If the consulted member is the same as the logged member, then this page will
 * propose to edit account parameters
 * </p>
 */
@ParamContainer("members/%member%")
public final class MemberPage extends ElveosPage {
    private final MemberPageUrl url;

    public final static String MEMBER_TAB_PANE = "tab";
    public final static String TASKS_TAB = "tasks";
    public final static String ACTIVITY_TAB = "history";
    public final static String ACCOUNT_TAB = "account";
    public final static String INVOICING_TAB = "invoicing";
    public final static String DASHBOARD_TAB = "dashboard";

    @SubParamContainer
    private HistoryTab history;

    @SubParamContainer
    private DashboardTab dashboard;

    @RequestParam(name = MEMBER_TAB_PANE)
    @Optional(ACTIVITY_TAB)
    private final String activeTabKey;

    @NonOptional(@tr("You have to specify a member number."))
    @RequestParam(role = Role.PAGENAME, message = @tr("I cannot find the member number: ''%value%''."))
    private final Member member;

    public MemberPage(final MemberPageUrl url) {
        super(url);
        this.url = url;
        this.member = url.getMember();
        this.activeTabKey = url.getActiveTabKey();
    }

    @Override
    protected HtmlElement createBodyContent() throws RedirectException {
        final TwoColumnLayout layout = new TwoColumnLayout(false, url);

        boolean myPage;
        if (AuthToken.isAuthenticated() && member != null && member.equals(AuthToken.getMember())) {
            myPage = true;
        } else {
            myPage = false;
        }

        layout.addLeft(generateMemberPageMain(myPage));

        if (member.canGetInternalAccount()) {
            layout.addLeft(generateTabPane());
        }

        // Adding activity page link

        final ActivityPageUrl activityPageUrl = new ActivityPageUrl();
        activityPageUrl.setMember(member);

        if (myPage) {
            layout.addRight(new SideBarButton(Context.tr("My activity"), activityPageUrl, WebConfiguration.getImgActivitySmall(), false));
        } else if(member.getFollowedFeatures().size() > 0){
            layout.addRight(new SideBarButton(Context.tr("{0}''s activity", member.getDisplayName()),
                                              activityPageUrl,
                                              WebConfiguration.getImgActivitySmall(),
                                              false));
        }

        // Adding list of teams
        final TitleSideBarElementLayout teamBlock = new TitleSideBarElementLayout();
        try {
            if (myPage) {
                teamBlock.setTitle(Context.tr("My teams"));
{'fraction_non_alphanumeric': 0.09249702262802699, 'fraction_numerical': 0.0010321556173084557, 'mean_word_length': 3.9964299880999605, 'pattern_counts': {'":': 0, '<': 13, '<?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': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '533224', 'n_tokens_mistral': 3571, 'n_tokens_neox': 3491, 'n_words': 811}