Commit 212945f3a6980f1eaa8568eccd9b2e7f7e2b8f3a

Authored by Ábner Oliveira
2 parents 9849cd64 cd461555

Merge branch 'new-item-menu' into 'master'

New item menu

See merge request !25
src/app/article/content-viewer/navbar-actions.html
1 1 <ul class="nav navbar-nav">
2   - <li ng-show="vm.profile">
3   - <a ng-show="vm.parentId" href="#" role="button" ui-sref="main.cms({profile: vm.profile.identifier, parent_id: vm.parentId})">
4   - <i class="fa fa-file fa-fw fa-lg"></i> {{"navbar.content_viewer_actions.new_post" | translate}}
5   - </a>
6   - </li>
7   - <li ng-show="vm.profile">
8   - <a href="#" role="button" ui-sref="main.cms({profile: vm.profile.identifier, parent_id: vm.parentId, type: 'CommentParagraphPlugin::Discussion'})">
9   - <i class="fa fa-file fa-fw fa-lg"></i> {{"navbar.content_viewer_actions.new_post" | translate}}
10   - </a>
11   - </li>
  2 + <li class="dropdown profile-menu" uib-dropdown>
  3 + <a class="btn dropdown-toggle" data-toggle="dropdown" uib-dropdown-toggle>
  4 + {{"navbar.content_viewer_actions.new_item" | translate}}
  5 + <i class="fa fa-caret-down"></i>
  6 + </a>
  7 + <ul class="dropdown-menu" uib-dropdown-menu ng-show="vm.profile">
  8 + <li ng-show="vm.parentId">
  9 + <a href="#" ui-sref="main.cms({profile: vm.profile.identifier, parent_id: vm.parentId})">
  10 + <i class="fa fa-file fa-fw fa-lg"></i> {{"navbar.content_viewer_actions.new_post" | translate}}
  11 + </a>
  12 + </li>
  13 + <li>
  14 + <a href="#" ui-sref="main.cms({profile: vm.profile.identifier, parent_id: vm.parentId, type: 'CommentParagraphPlugin::Discussion'})">
  15 + <i class="fa fa-file fa-fw fa-lg"></i> {{"navbar.content_viewer_actions.new_discussion" | translate}}
  16 + </a>
  17 + </li>
  18 + </ul>
  19 + </li>
  20 +
12 21 </ul>
  22 +
... ...
src/app/article/content-viewer/navbar-actions.spec.ts 0 → 100644
... ... @@ -0,0 +1,53 @@
  1 +import {TestComponentBuilder} from 'ng-forward/cjs/testing/test-component-builder';
  2 +import {Provider} from 'ng-forward';
  3 +import {ComponentTestHelper, createClass} from "./../../../spec/component-test-helper";
  4 +import {providers} from 'ng-forward/cjs/testing/providers';
  5 +import {ContentViewerActionsComponent} from '././content-viewer-actions.component';
  6 +import * as helpers from "../../../spec/helpers";
  7 +
  8 +const htmlTemplate: string = '<content-viewer-actions [article]="ctrl.article" [profile]="ctrl.profile"></content-viewer-actions>';
  9 +
  10 +describe("Components", () => {
  11 +
  12 + describe("Content Viewer Actions Component", () => {
  13 + let serviceMock = {
  14 + getEnvironmentPeople: (filters: any): any => {
  15 + return Promise.resolve([{ identifier: "person1" }]);
  16 + }
  17 + };
  18 + let providers = [
  19 + new Provider('ArticleService', { useValue: helpers.mocks.articleService }),
  20 + new Provider('ProfileService', { useValue: helpers.mocks.profileService })
  21 + ];
  22 +
  23 + let helper: ComponentTestHelper<ContentViewerActionsComponent>;
  24 +
  25 + beforeEach(angular.mock.module("templates"));
  26 +
  27 + /**
  28 + * The beforeEach procedure will initialize the helper and parse
  29 + * the component according to the given providers. Unfortunetly, in
  30 + * this mode, the providers and properties given to the construtor
  31 + * can't be overriden.
  32 + */
  33 + beforeEach((done) => {
  34 + // Create the component bed for the test. Optionally, this could be done
  35 + // in each test if one needs customization of these parameters per test
  36 + let cls = createClass({
  37 + template: htmlTemplate,
  38 + directives: [ContentViewerActionsComponent],
  39 + providers: providers,
  40 + properties: {}
  41 + });
  42 + helper = new ComponentTestHelper<ContentViewerActionsComponent>(cls, done);
  43 + });
  44 +
  45 + it("render the actions new item menu", () => {
  46 + expect(helper.all("a[class|='btn dropdown-toggle']")[0]).not.toBeNull();
  47 + });
  48 +
  49 + it("render two menu item actions", () => {
  50 + expect(helper.all("ul")[1].find("li").length).toBe(2);
  51 + });
  52 + });
  53 +});
... ...
src/app/profile/navbar-actions.html 0 → 100644
... ... @@ -0,0 +1,18 @@
  1 +<ul class="nav navbar-nav">
  2 + <li class="dropdown profile-menu" uib-dropdown>
  3 + <a class="btn dropdown-toggle" data-toggle="dropdown" uib-dropdown-toggle>
  4 + {{"navbar.profile_actions.new_item" | translate}}
  5 + <i class="fa fa-caret-down"></i>
  6 + </a>
  7 + <ul class="dropdown-menu" uib-dropdown-menu ng-show="vm.profile">
  8 + <!-- FIXED HERE BUT SHOULD BE A HOTSPOT TO INCLUDE LINKS FROM THE PLUGIN -->
  9 + <li>
  10 + <a href="#" ui-sref="main.cms({profile: vm.profile.identifier, parent_id: null, type: 'CommentParagraphPlugin::Discussion'})">
  11 + <i class="fa fa-file fa-fw fa-lg"></i> {{"navbar.profile_actions.new_discussion" | translate}}
  12 + </a>
  13 + </li>
  14 + </ul>
  15 + </li>
  16 +
  17 +</ul>
  18 +
... ...
src/app/profile/profile-actions.component.ts 0 → 100644
... ... @@ -0,0 +1,21 @@
  1 +import {Component, Inject, provide} from "ng-forward";
  2 +import {ProfileService} from "../../lib/ng-noosfero-api/http/profile.service";
  3 +
  4 +@Component({
  5 + selector: "profile-actions",
  6 + templateUrl: "app/article/content-viewer/navbar-actions.html",
  7 + providers: [
  8 + provide('profileService', { useClass: ProfileService })
  9 + ]
  10 +})
  11 +@Inject(ProfileService)
  12 +export class ProfileActionsComponent {
  13 + profile: noosfero.Profile;
  14 + parentId: number;
  15 +
  16 + constructor(profileService: ProfileService) {
  17 + profileService.getCurrentProfile().then((profile: noosfero.Profile) => {
  18 + this.profile = profile;
  19 + });
  20 + }
  21 +}
... ...
src/app/profile/profile.component.ts
... ... @@ -9,7 +9,7 @@ import {ActivitiesComponent} from &quot;./activities/activities.component&quot;;
9 9 import {ProfileService} from "../../lib/ng-noosfero-api/http/profile.service";
10 10 import {NotificationService} from "../shared/services/notification.service";
11 11 import {MyProfileComponent} from "./myprofile.component";
12   -
  12 +import {ProfileActionsComponent} from "./profile-actions.component";
13 13  
14 14 /**
15 15 * @ngdoc controller
... ... @@ -37,13 +37,25 @@ import {MyProfileComponent} from &quot;./myprofile.component&quot;;
37 37 templateUrl: "app/profile/info/profile-info.html",
38 38 controller: ProfileInfoComponent,
39 39 controllerAs: "vm"
  40 + },
  41 + "actions@main": {
  42 + templateUrl: "app/profile/navbar-actions.html",
  43 + controller: ProfileActionsComponent,
  44 + controllerAs: "vm"
40 45 }
41 46 }
42 47 },
43 48 {
44 49 name: 'main.profile.settings',
45 50 url: "^/myprofile/:profile",
46   - component: MyProfileComponent
  51 + component: MyProfileComponent,
  52 + views: {
  53 + "actions@main": {
  54 + templateUrl: "app/profile/navbar-actions.html",
  55 + controller: ProfileActionsComponent,
  56 + controllerAs: "vm"
  57 + }
  58 + }
47 59 },
48 60 {
49 61 name: 'main.cms',
... ...
src/languages/en.json
... ... @@ -24,7 +24,12 @@
24 24 "auth.form.login": "Login / Email address",
25 25 "auth.form.password": "Password",
26 26 "auth.form.login_button": "Login",
  27 + "navbar.content_viewer_actions.new_item": "New Item",
  28 + "navbar.profile_actions.new_item": "New Item",
27 29 "navbar.content_viewer_actions.new_post": "New Post",
  30 + "//TODO": "Create a way to load plugin translatios - Move plugins translations to the plugins translations files",
  31 + "navbar.content_viewer_actions.new_discussion": "New Discussion",
  32 + "navbar.profile_actions.new_discussion": "New Discussion",
28 33 "notification.error.default.message": "Something went wrong!",
29 34 "notification.error.default.title": "Oops...",
30 35 "notification.profile.not_found": "Page not found",
... ...
src/languages/pt.json
... ... @@ -24,7 +24,9 @@
24 24 "auth.form.login": "Login / Email",
25 25 "auth.form.password": "Senha",
26 26 "auth.form.login_button": "Login",
  27 + "navbar.content_viewer_actions.new_item": "Novo Item",
27 28 "navbar.content_viewer_actions.new_post": "Novo Artigo",
  29 + "navbar.content_viewer_actions.new_discussion": "Nova Discussão",
28 30 "notification.error.default.message": "Algo deu errado!",
29 31 "notification.error.default.title": "Oops...",
30 32 "notification.profile.not_found": "Página não encontrada",
... ...