Create new page_tabs template

- Replace explicit tabs in profile contacts page with new template
This commit is contained in:
Hypolite Petovan 2020-08-06 10:34:11 -04:00
parent f5ea07c731
commit 383ddb10ed
8 changed files with 57 additions and 49 deletions

View File

@ -171,4 +171,40 @@ abstract class BaseModule
throw new \Friendica\Network\HTTPException\ForbiddenException();
}
}
protected static function getContactFilterTabs(string $baseUrl, string $current, bool $displayCommonTab)
{
$tabs = [
[
'label' => DI::l10n()->t('All contacts'),
'url' => $baseUrl . '/contacts',
'sel' => !$current || $current == 'all' ? 'active' : '',
],
[
'label' => DI::l10n()->t('Followers'),
'url' => $baseUrl . '/contacts/followers',
'sel' => $current == 'followers' ? 'active' : '',
],
[
'label' => DI::l10n()->t('Following'),
'url' => $baseUrl . '/contacts/following',
'sel' => $current == 'following' ? 'active' : '',
],
[
'label' => DI::l10n()->t('Mutual friends'),
'url' => $baseUrl . '/contacts/mutuals',
'sel' => $current == 'mutuals' ? 'active' : '',
],
];
if ($displayCommonTab) {
$tabs[] = [
'label' => DI::l10n()->t('Common'),
'url' => $baseUrl . '/contacts/common',
'sel' => $current == 'common' ? 'active' : '',
];
}
return $tabs;
}
}

View File

@ -53,8 +53,6 @@ class Common extends BaseProfile
throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
}
$o = self::getTabsHTML($a, 'contacts', false, $nickname);
if (!empty($a->profile['hide-friends'])) {
throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
}
@ -65,6 +63,10 @@ class Common extends BaseProfile
$a->redirect('profile/' . $nickname . '/contacts');
};
$o = self::getTabsHTML($a, 'contacts', false, $nickname);
$tabs = self::getContactFilterTabs('profile/' . $nickname, 'common', $displayCommonTab);
$sourceId = Contact::getIdForURL(Profile::getMyURL());
$targetId = Contact::getPublicIdByUserId($a->profile['uid']);
@ -92,15 +94,8 @@ class Common extends BaseProfile
$o .= Renderer::replaceMacros($tpl, [
'$title' => $title,
'$desc' => $desc,
'$nickname' => $nickname,
'$type' => 'common',
'$displayCommonTab' => $displayCommonTab,
'$tabs' => $tabs,
'$all_label' => DI::l10n()->t('All contacts'),
'$followers_label' => DI::l10n()->t('Followers'),
'$following_label' => DI::l10n()->t('Following'),
'$mutuals_label' => DI::l10n()->t('Mutual friends'),
'$common_label' => DI::l10n()->t('Common'),
'$noresult_label' => DI::l10n()->t('No common contacts.'),
'$contacts' => $contacts,

View File

@ -61,6 +61,8 @@ class Contacts extends Module\BaseProfile
$o = self::getTabsHTML($a, 'contacts', $is_owner, $nickname);
$tabs = self::getContactFilterTabs('profile/' . $nickname, $type, Session::isAuthenticated() && $a->profile['uid'] != local_user());
$condition = [
'uid' => $a->profile['uid'],
'blocked' => false,
@ -113,15 +115,8 @@ class Contacts extends Module\BaseProfile
$o .= Renderer::replaceMacros($tpl, [
'$title' => $title,
'$desc' => $desc,
'$nickname' => $nickname,
'$type' => $type,
'$displayCommonTab' => Session::isAuthenticated() && $a->profile['uid'] != local_user(),
'$tabs' => $tabs,
'$all_label' => DI::l10n()->t('All contacts'),
'$followers_label' => DI::l10n()->t('Followers'),
'$following_label' => DI::l10n()->t('Following'),
'$mutuals_label' => DI::l10n()->t('Mutual friends'),
'$common_label' => DI::l10n()->t('Common'),
'$noresult_label' => DI::l10n()->t('No contacts.'),
'$contacts' => $contacts,

View File

@ -0,0 +1 @@
{{include file="common_tabs.tpl" tabs=$tabs}}

View File

@ -5,15 +5,8 @@
<p>{{$desc nofilter}}</p>
{{/if}}
<ul role="menubar" class="tabs">
<li role="menuitem"><a href="profile/{{$nickname}}/contacts" class="tab button{{if !$type || $type == 'all'}} active{{/if}}">{{$all_label}}</a></li>
<li role="menuitem"><a href="profile/{{$nickname}}/contacts/followers" class="tab button{{if $type == 'followers'}} active{{/if}}">{{$followers_label}}</a></li>
<li role="menuitem"><a href="profile/{{$nickname}}/contacts/following" class="tab button{{if $type == 'following'}} active{{/if}}">{{$following_label}}</a></li>
<li role="menuitem"><a href="profile/{{$nickname}}/contacts/mutuals" class="tab button{{if $type == 'mutuals'}} active{{/if}}">{{$mutuals_label}}</a></li>
{{if $displayCommonTab}}
<li role="menuitem"><a href="profile/{{$nickname}}/contacts/common" class="tab button{{if $type == 'common'}} active{{/if}}{{if !$common_count}} disabled{{/if}}">{{$common_label}}</a></li>
{{/if}}
</ul>
{{include file="page_tabs.tpl" tabs=$tabs}}
{{if $contacts}}
<div id="viewcontact_wrapper-{{$id}}">
{{foreach $contacts as $contact}}

View File

@ -4,7 +4,7 @@
<ul role="menubar" class="tabbar list-inline visible-lg visible-md visible-sm hidden-xs">
{{* The normal tabbar *}}
<li>
<ul class="tabs flex-nav" role="menu" >
<ul class="tabs flex-nav" role="menu" >
{{foreach $tabs as $tab}}
<li id="{{$tab.id}}" role="presentation" {{if $tab.sel}} class="{{$tab.sel}}" {{/if}}><a role="menuitem" href="{{$tab.url}}" {{if $tab.accesskey}}accesskey="{{$tab.accesskey}}"{{/if}} {{if $tab.title}} title="{{$tab.title}}"{{/if}}>{{$tab.label}}</a></li>
{{/foreach}}
@ -36,8 +36,6 @@
{{$exttabs[]=$tab}}
{{/if}}
{{/foreach}}
</ul>
</li>

View File

@ -0,0 +1,7 @@
<ul class="nav nav-tabs">
{{foreach $tabs as $tab}}
<li id="{{$tab.id}}" role="presentation"{{if $tab.sel}} class="{{$tab.sel}}"{{/if}}>
<a role="menuitem" href="{{$tab.url}}"{{if $tab.accesskey}} accesskey="{{$tab.accesskey}}"{{/if}}{{if $tab.title}} title="{{$tab.title}}"{{/if}}>{{$tab.label}}</a>
</li>
{{/foreach}}
</ul>

View File

@ -5,25 +5,8 @@
<p>{{$desc nofilter}}</p>
{{/if}}
<ul class="nav nav-tabs">
<li role="presentation"{{if !$type || $type == 'all'}} class="active"{{/if}}>
<a href="profile/{{$nickname}}/contacts">{{$all_label}}</a>
</li>
<li role="presentation"{{if $type == 'followers'}} class="active"{{/if}}>
<a href="profile/{{$nickname}}/contacts/followers">{{$followers_label}}</a>
</li>
<li role="presentation"{{if $type == 'following'}} class="active"{{/if}}>
<a href="profile/{{$nickname}}/contacts/following">{{$following_label}}</a>
</li>
<li role="presentation"{{if $type == 'mutuals'}} class="active"{{/if}}>
<a href="profile/{{$nickname}}/contacts/mutuals">{{$mutuals_label}}</a>
</li>
{{if $displayCommonTab}}
<li role="presentation"{{if $type == 'common'}} class="active"{{/if}}>
<a href="profile/{{$nickname}}/contacts/common" class="tab button">{{$common_label}}</a>
</li>
{{/if}}
</ul>
{{include file="page_tabs.tpl" tabs=$tabs}}
{{if $contacts}}
<ul id="viewcontact_wrapper{{if $id}}-{{$id}}{{/if}}" class="viewcontact_wrapper media-list">
{{foreach $contacts as $contact}}