diff --git a/.vscode/settings.json b/.vscode/settings.json
index 7e91822..a09ced7 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -3,7 +3,9 @@
"files.exclude": {
"**/.git": true,
"**/.DS_Store": true,
- "src/app/*.js": false
+ "src/**/*.js": true,
+ "src/**/*.js.map": true,
+ "coverage": true
},
"editor.fontSize": 14,
"typescript.useCodeSnippetsOnMethodSuggest": true
diff --git a/src/app/admin/index.ts b/src/app/admin/index.ts
new file mode 100644
index 0000000..4206e70
--- /dev/null
+++ b/src/app/admin/index.ts
@@ -0,0 +1 @@
+/* Module Index Entry - generated using the script npm run generate-index */
diff --git a/src/app/article/article-default-view-component.spec.ts b/src/app/article/article-default-view-component.spec.ts
new file mode 100644
index 0000000..7158586
--- /dev/null
+++ b/src/app/article/article-default-view-component.spec.ts
@@ -0,0 +1,108 @@
+
+import {Input, provide, Component} from 'ng-forward';
+import {ArticleViewComponent, ArticleDefaultViewComponent} from './article-default-view.component';
+
+import {createComponentFromClass, quickCreateComponent} from "../../spec/helpers";
+
+// this htmlTemplate will be re-used between the container components in this spec file
+const htmlTemplate: string = ' ';
+
+
+describe("Components", () => {
+
+ describe("ArticleView Component", () => {
+
+ // the karma preprocessor html2js transform the templates html into js files which put
+ // the templates to the templateCache into the module templates
+ // we need to load the module templates here as the template for the
+ // component Noosfero ArtileView will be load on our tests
+ beforeEach(angular.mock.module("templates"));
+
+ it("renders the default component when no specific component is found", (done: Function) => {
+ // Creating a container component (ArticleContainerComponent) to include
+ // the component under test (ArticleView)
+ @Component({ selector: 'test-container-component', template: htmlTemplate, directives: [ArticleViewComponent] })
+ class ArticleContainerComponent {
+ article = { type: 'anyArticleType' };
+ profile = { name: 'profile-name' };
+ constructor() {
+ }
+ }
+
+ createComponentFromClass(ArticleContainerComponent).then((fixture) => {
+ // and here we can inspect and run the test assertions
+
+ // gets the children component of ArticleContainerComponent
+ let articleView: ArticleViewComponent = fixture.debugElement.componentViewChildren[0].componentInstance;
+
+ // and checks if the article View rendered was the Default Article View
+ expect(articleView.constructor.prototype).toEqual(ArticleDefaultViewComponent.prototype);
+
+ // done needs to be called (it isn't really needed, as we can read in
+ // here (https://github.com/ngUpgraders/ng-forward/blob/master/API.md#createasync)
+ // because createAsync in ng-forward is not really async, but as the intention
+ // here is write tests in angular 2 ways, this is recommended
+ done();
+ });
+
+ });
+
+ it("receives the article and profile as inputs", (done: Function) => {
+
+ // Creating a container component (ArticleContainerComponent) to include
+ // the component under test (ArticleView)
+ @Component({ selector: 'test-container-component', template: htmlTemplate, directives: [ArticleViewComponent] })
+ class ArticleContainerComponent {
+ article = { type: 'anyArticleType' };
+ profile = { name: 'profile-name' };
+ constructor() {
+ }
+ }
+
+ // uses the TestComponentBuilder instance to initialize the component
+ createComponentFromClass(ArticleContainerComponent).then((fixture) => {
+ // and here we can inspect and run the test assertions
+ let articleView: ArticleViewComponent = fixture.debugElement.componentViewChildren[0].componentInstance;
+
+ // assure the article object inside the ArticleView matches
+ // the provided through the parent component
+ expect(articleView.article.type).toEqual("anyArticleType");
+ expect(articleView.profile.name).toEqual("profile-name");
+
+ // done needs to be called (it isn't really needed, as we can read in
+ // here (https://github.com/ngUpgraders/ng-forward/blob/master/API.md#createasync)
+ // because createAsync in ng-forward is not really async, but as the intention
+ // here is write tests in angular 2 ways, this is recommended
+ done();
+ });
+ });
+
+
+ it("renders a article view which matches to the article type", done => {
+ // NoosferoTinyMceArticle component created to check if it will be used
+ // when a article with type 'TinyMceArticle' is provided to the noosfero-article (ArticleView)
+ // *** Important *** - the selector is what ng-forward uses to define the name of the directive provider
+ @Component({ selector: 'noosfero-tiny-mce-article', template: "
TinyMceArticle " })
+ class TinyMceArticleView {
+ @Input() article: any;
+ @Input() profile: any;
+ }
+
+ // Creating a container component (ArticleContainerComponent) to include our NoosferoTinyMceArticle
+ @Component({ selector: 'test-container-component', template: htmlTemplate, directives: [ArticleViewComponent, TinyMceArticleView] })
+ class CustomArticleType {
+ article = { type: 'TinyMceArticle' };
+ profile = { name: 'profile-name' };
+ constructor() {
+ }
+ }
+ createComponentFromClass(CustomArticleType).then(fixture => {
+ let myComponent: CustomArticleType = fixture.componentInstance;
+ expect(myComponent.article.type).toEqual("TinyMceArticle");
+ expect(fixture.debugElement.componentViewChildren[0].text()).toEqual("TinyMceArticle");
+ done();
+ });
+ });
+
+ });
+});
\ No newline at end of file
diff --git a/src/app/article/article-default-view.component.ts b/src/app/article/article-default-view.component.ts
new file mode 100644
index 0000000..f8fe0ee
--- /dev/null
+++ b/src/app/article/article-default-view.component.ts
@@ -0,0 +1,57 @@
+import { bundle, Input, Inject, Component, Directive } from 'ng-forward';
+import {ArticleBlogComponent} from "./types/blog/blog.component";
+
+/**
+ * @ngdoc controller
+ * @name ArticleDefaultView
+ * @description
+ * A default view for Noosfero Articles. If the specific article view is
+ * not implemented, then this view is used.
+ */
+@Component({
+ selector: 'noosfero-default-article',
+ templateUrl: 'app/article/article.html'
+})
+export class ArticleDefaultViewComponent {
+
+ @Input() article: noosfero.Article;
+ @Input() profile: noosfero.Profile;
+
+}
+
+/**
+ * @ngdoc controller
+ * @name ArticleView
+ * @description
+ * A dynamic view for articles. It uses the article type to replace
+ * the default template with the custom article directive.
+ */
+@Component({
+ selector: 'noosfero-article',
+ template: 'not-used',
+ directives: [ArticleDefaultViewComponent, ArticleBlogComponent]
+})
+@Inject("$element", "$scope", "$injector", "$compile")
+export class ArticleViewComponent {
+
+ @Input() article: noosfero.Article;
+ @Input() profile: noosfero.Profile;
+ directiveName: string;
+
+ ngOnInit() {
+ let specificDirective = 'noosfero' + this.article.type;
+ this.directiveName = "noosfero-default-article";
+ if (this.$injector.has(specificDirective + 'Directive')) {
+ this.directiveName = specificDirective.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
+ }
+ this.$element.replaceWith(this.$compile('<' + this.directiveName + ' [article]="ctrl.article" [profile]="ctrl.profile">' + this.directiveName + '>')(this.$scope));
+ }
+
+ constructor(
+ private $element: any,
+ private $scope: ng.IScope,
+ private $injector: ng.auto.IInjectorService,
+ private $compile: ng.ICompileService) {
+
+ }
+}
diff --git a/src/app/article/article.html b/src/app/article/article.html
new file mode 100644
index 0000000..0a94109
--- /dev/null
+++ b/src/app/article/article.html
@@ -0,0 +1,23 @@
+
diff --git a/src/app/article/article.scss b/src/app/article/article.scss
new file mode 100644
index 0000000..59b91e2
--- /dev/null
+++ b/src/app/article/article.scss
@@ -0,0 +1,17 @@
+.article {
+ .page-info {
+ .author {
+ a {
+ color: #b4bcc2;
+ }
+ }
+ }
+
+ .page-header {
+ margin-bottom: 5px;
+ }
+
+ .sub-header {
+ margin-bottom: 20px;
+ }
+}
diff --git a/src/app/article/basic-editor.component.spec.ts b/src/app/article/basic-editor.component.spec.ts
new file mode 100644
index 0000000..70d987d
--- /dev/null
+++ b/src/app/article/basic-editor.component.spec.ts
@@ -0,0 +1,55 @@
+import {quickCreateComponent} from "../../spec/helpers";
+import {BasicEditorComponent} from "./basic-editor.component";
+
+
+describe("Article BasicEditor", () => {
+
+ let $rootScope: ng.IRootScopeService;
+ let $q: ng.IQService;
+ let articleServiceMock: any;
+ let profileServiceMock: any;
+ let $state: any;
+ let profile = { id: 1 };
+ let notification: any;
+
+
+ beforeEach(inject((_$rootScope_: ng.IRootScopeService, _$q_: ng.IQService) => {
+ $rootScope = _$rootScope_;
+ $q = _$q_;
+ }));
+
+ beforeEach(() => {
+ $state = jasmine.createSpyObj("$state", ["transitionTo"]);
+ notification = jasmine.createSpyObj("notification", ["success"]);
+ profileServiceMock = jasmine.createSpyObj("profileServiceMock", ["getCurrentProfile"]);
+ articleServiceMock = jasmine.createSpyObj("articleServiceMock", ["createInProfile"]);
+
+ let getCurrentProfileResponse = $q.defer();
+ getCurrentProfileResponse.resolve(profile);
+
+ let articleCreate = $q.defer();
+ articleCreate.resolve({ data: { path: "path", profile: { identifier: "profile" } } });
+
+ profileServiceMock.getCurrentProfile = jasmine.createSpy("getCurrentProfile").and.returnValue(getCurrentProfileResponse.promise);
+ articleServiceMock.createInProfile = jasmine.createSpy("createInProfile").and.returnValue(articleCreate.promise);
+ });
+
+ it("create an article in the current profile when save", done => {
+ let component: BasicEditorComponent = new BasicEditorComponent(articleServiceMock, profileServiceMock, $state, notification);
+ component.save();
+ $rootScope.$apply();
+ expect(profileServiceMock.getCurrentProfile).toHaveBeenCalled();
+ expect(articleServiceMock.createInProfile).toHaveBeenCalledWith(profile, component.article);
+ done();
+ });
+
+ it("got to the new article page and display an alert when saving sucessfully", done => {
+ let component: BasicEditorComponent = new BasicEditorComponent(articleServiceMock, profileServiceMock, $state, notification);
+ component.save();
+ $rootScope.$apply();
+ expect($state.transitionTo).toHaveBeenCalledWith("main.profile.page", { page: "path", profile: "profile" });
+ expect(notification.success).toHaveBeenCalled();
+ done();
+ });
+
+});
diff --git a/src/app/article/basic-editor.component.ts b/src/app/article/basic-editor.component.ts
new file mode 100644
index 0000000..98cc859
--- /dev/null
+++ b/src/app/article/basic-editor.component.ts
@@ -0,0 +1,35 @@
+import {StateConfig, Component, Inject, provide} from 'ng-forward';
+import {ArticleService} from "../../lib/ng-noosfero-api/http/article.service";
+import {ProfileService} from "../../lib/ng-noosfero-api/http/profile.service";
+import {NotificationService} from "../shared/services/notification.service.ts";
+
+@Component({
+ selector: 'article-basic-editor',
+ templateUrl: "app/article/basic-editor.html",
+ providers: [
+ provide('articleService', { useClass: ArticleService }),
+ provide('profileService', { useClass: ProfileService }),
+ provide('notification', { useClass: NotificationService })
+ ]
+})
+@Inject(ArticleService, ProfileService, "$state", NotificationService)
+export class BasicEditorComponent {
+
+ article: noosfero.Article = {};
+
+ constructor(private articleService: ArticleService,
+ private profileService: ProfileService,
+ private $state: ng.ui.IStateService,
+ private notification: NotificationService) { }
+
+ save() {
+ this.profileService.getCurrentProfile().then((profile: noosfero.Profile) => {
+ return this.articleService.createInProfile(profile, this.article);
+ }).then((response: noosfero.RestResult) => {
+ let article = (response.data);
+ this.$state.transitionTo('main.profile.page', { page: article.path, profile: article.profile.identifier });
+ this.notification.success("Good job!", "Article saved!");
+ });
+ }
+
+}
diff --git a/src/app/article/basic-editor.html b/src/app/article/basic-editor.html
new file mode 100644
index 0000000..5146869
--- /dev/null
+++ b/src/app/article/basic-editor.html
@@ -0,0 +1,11 @@
+
diff --git a/src/app/article/content-viewer/content-viewer-actions.component.spec.ts b/src/app/article/content-viewer/content-viewer-actions.component.spec.ts
new file mode 100644
index 0000000..71ca1de
--- /dev/null
+++ b/src/app/article/content-viewer/content-viewer-actions.component.spec.ts
@@ -0,0 +1,67 @@
+import {providers} from 'ng-forward/cjs/testing/providers';
+
+import {Input, Component, provide} from 'ng-forward';
+
+import * as helpers from "../../../spec/helpers";
+
+import {ComponentFixture} from 'ng-forward/cjs/testing/test-component-builder';
+import {ContentViewerActions} from './content-viewer-actions.component';
+
+// this htmlTemplate will be re-used between the container components in this spec file
+const htmlTemplate: string = ' ';
+
+describe('Content Viewer Actions Component', () => {
+
+ beforeEach(() => {
+
+ angular.mock.module("templates");
+
+ providers((provide: any) => {
+ return [
+ provide('ProfileService', {
+ useValue: helpers.mocks.profileService
+ })
+ ];
+ });
+ });
+
+ let buildComponent = (): Promise => {
+ return helpers.quickCreateComponent({
+ providers: [
+ helpers.provideEmptyObjects('Restangular'),
+ helpers.provideFilters('translateFilter')
+ ],
+ directives: [ContentViewerActions],
+ template: htmlTemplate
+ });
+ };
+
+ it('renders content viewer actions directive', (done: Function) => {
+ buildComponent().then((fixture: ComponentFixture) => {
+ expect(fixture.debugElement.query('content-viewer-actions').length).toEqual(1);
+
+ done();
+ });
+ });
+
+ it('check if profile was loaded', (done: Function) => {
+ let profile: any = {
+ id: 1,
+ identifier: 'the-profile-test',
+ type: 'Person'
+ };
+
+ helpers.mocks.profileService.getCurrentProfile = () => {
+ return helpers.mocks.promiseResultTemplate(profile);
+ };
+
+ buildComponent().then((fixture: ComponentFixture) => {
+ let contentViewerComp: ContentViewerActions = fixture.debugElement.componentViewChildren[0].componentInstance;
+
+ expect(contentViewerComp.profile).toEqual(jasmine.objectContaining(profile));
+
+ done();
+ });
+ });
+
+});
diff --git a/src/app/article/content-viewer/content-viewer-actions.component.ts b/src/app/article/content-viewer/content-viewer-actions.component.ts
new file mode 100644
index 0000000..be0d629
--- /dev/null
+++ b/src/app/article/content-viewer/content-viewer-actions.component.ts
@@ -0,0 +1,20 @@
+import {Component, Inject, provide} from "ng-forward";
+import {ProfileService} from "../../../lib/ng-noosfero-api/http/profile.service";
+
+@Component({
+ selector: "content-viewer-actions",
+ templateUrl: "app/article/content-viewer/navbar-actions.html",
+ providers: [provide('profileService', { useClass: ProfileService })]
+})
+@Inject(ProfileService)
+export class ContentViewerActions {
+
+ article: noosfero.Article;
+ profile: noosfero.Profile;
+
+ constructor(profileService: ProfileService) {
+ profileService.getCurrentProfile().then((profile: noosfero.Profile) => {
+ this.profile = profile;
+ });
+ }
+}
diff --git a/src/app/article/content-viewer/content-viewer.component.spec.ts b/src/app/article/content-viewer/content-viewer.component.spec.ts
new file mode 100644
index 0000000..7b3501d
--- /dev/null
+++ b/src/app/article/content-viewer/content-viewer.component.spec.ts
@@ -0,0 +1,88 @@
+import {providers} from 'ng-forward/cjs/testing/providers';
+
+import {Input, Component, provide} from 'ng-forward';
+
+import * as helpers from "../../../spec/helpers";
+
+import {ComponentFixture} from 'ng-forward/cjs/testing/test-component-builder';
+import {ContentViewerComponent} from './content-viewer.component';
+
+// this htmlTemplate will be re-used between the container components in this spec file
+const htmlTemplate: string = ' ';
+
+describe('Content Viewer Component', () => {
+
+ let stateParamsService: any;
+
+ // loading the templates
+ beforeEach(() => {
+ angular.mock.module("templates");
+
+ stateParamsService = { page: 1 };
+
+ providers((provide: any) => {
+ return [
+ provide('ArticleService', {
+ useValue: helpers.mocks.articleService
+ }),
+ provide('ProfileService', {
+ useValue: helpers.mocks.profileService
+ }),
+ // TODO: Como criar um mock do atributo "page" de stateParams
+ provide('$stateParams', {
+ useValue: stateParamsService
+ })
+ ];
+ });
+ });
+
+ let buildComponent = (): Promise => {
+ return helpers.quickCreateComponent({
+ providers: [
+ helpers.provideEmptyObjects('Restangular')
+ ],
+ directives: [ContentViewerComponent],
+ template: htmlTemplate
+ });
+ };
+
+ it('renders content viewer directive', (done: Function) => {
+ buildComponent().then((fixture: ComponentFixture) => {
+ expect(fixture.debugElement.query('content-viewer').length).toEqual(1);
+
+ done();
+ });
+ });
+
+ it('check if article was loaded', (done: Function) => {
+ let article: any = {
+ id: 1,
+ title: 'The article test'
+ };
+ let profile: any = {
+ id: 1,
+ identifier: 'the-profile-test',
+ type: 'Person'
+ };
+
+ helpers.mocks.profileService.getCurrentProfile = () => {
+ return helpers.mocks.promiseResultTemplate(profile);
+ };
+
+ helpers.mocks.articleService.getArticleByProfileAndPath = (profile: noosfero.Profile, path: string) => {
+ return helpers.mocks.promiseResultTemplate({
+ data: article
+ });
+ };
+
+
+ buildComponent().then((fixture: ComponentFixture) => {
+ let contentViewerComp: ContentViewerComponent = fixture.debugElement.componentViewChildren[0].componentInstance;
+
+ expect(contentViewerComp.profile).toEqual(profile);
+ expect(contentViewerComp.article).toEqual(article);
+
+ done();
+ });
+ });
+});
diff --git a/src/app/article/content-viewer/content-viewer.component.ts b/src/app/article/content-viewer/content-viewer.component.ts
new file mode 100644
index 0000000..16d0741
--- /dev/null
+++ b/src/app/article/content-viewer/content-viewer.component.ts
@@ -0,0 +1,38 @@
+import {ArticleViewComponent} from "./../article-default-view.component";
+import {Input, Component, StateConfig, Inject, provide} from "ng-forward";
+
+import {ArticleBlogComponent} from "./../types/blog/blog.component";
+import {ArticleService} from "../../../lib/ng-noosfero-api/http/article.service";
+import {ProfileService} from "../../../lib/ng-noosfero-api/http/profile.service";
+
+@Component({
+ selector: "content-viewer",
+ templateUrl: "app/article/content-viewer/page.html",
+ directives: [ArticleBlogComponent, ArticleViewComponent],
+ providers: [
+ provide('articleService', { useClass: ArticleService }),
+ provide('profileService', { useClass: ProfileService })
+ ]
+})
+@Inject(ArticleService, ProfileService, "$log", "$stateParams")
+export class ContentViewerComponent {
+
+ @Input()
+ article: noosfero.Article = null;
+
+ @Input()
+ profile: noosfero.Profile = null;
+
+ constructor(private articleService: ArticleService, private profileService: ProfileService, private $log: ng.ILogService, private $stateParams: angular.ui.IStateParamsService) {
+ this.activate();
+ }
+
+ activate() {
+ this.profileService.getCurrentProfile().then((profile: noosfero.Profile) => {
+ this.profile = profile;
+ return this.articleService.getArticleByProfileAndPath(this.profile, this.$stateParams["page"]);
+ }).then((result: noosfero.RestResult) => {
+ this.article = result.data;
+ });
+ }
+}
diff --git a/src/app/article/content-viewer/index.ts b/src/app/article/content-viewer/index.ts
new file mode 100644
index 0000000..c9ffa0e
--- /dev/null
+++ b/src/app/article/content-viewer/index.ts
@@ -0,0 +1,3 @@
+/* Module Index Entry - generated using the script npm run generate-index */
+export * from "./content-viewer-actions.component";
+export * from "./content-viewer.component";
diff --git a/src/app/article/content-viewer/navbar-actions.html b/src/app/article/content-viewer/navbar-actions.html
new file mode 100644
index 0000000..1b0af5e
--- /dev/null
+++ b/src/app/article/content-viewer/navbar-actions.html
@@ -0,0 +1,7 @@
+
diff --git a/src/app/article/content-viewer/page.html b/src/app/article/content-viewer/page.html
new file mode 100644
index 0000000..1c842e3
--- /dev/null
+++ b/src/app/article/content-viewer/page.html
@@ -0,0 +1 @@
+
diff --git a/src/app/article/index.ts b/src/app/article/index.ts
new file mode 100644
index 0000000..ccafeea
--- /dev/null
+++ b/src/app/article/index.ts
@@ -0,0 +1,3 @@
+/* Module Index Entry - generated using the script npm run generate-index */
+export * from "./article-default-view.component";
+export * from "./basic-editor.component";
diff --git a/src/app/article/types/blog/blog.component.spec.ts b/src/app/article/types/blog/blog.component.spec.ts
new file mode 100644
index 0000000..ca7f5da
--- /dev/null
+++ b/src/app/article/types/blog/blog.component.spec.ts
@@ -0,0 +1,129 @@
+import {
+providers
+} from 'ng-forward/cjs/testing/providers';
+
+import {
+Input,
+Component
+} from 'ng-forward';
+import {
+ArticleBlogComponent
+} from './blog.component';
+
+import {
+createComponentFromClass,
+quickCreateComponent,
+provideEmptyObjects,
+createProviderToValue,
+provideFilters
+} from "../../../../spec/helpers.ts";
+
+// this htmlTemplate will be re-used between the container components in this spec file
+const htmlTemplate: string = ' ';
+
+describe("Blog Component", () => {
+
+ function promiseResultTemplate(response?: {}) {
+ let thenFuncEmpty = (func: Function) => {
+ // does nothing
+ };
+ if (response) {
+ return {
+ then: (func: (response: any) => void) => {
+ func(response);
+ }
+ };
+ } else {
+ return {
+ then: (func: (response: any) => void) => {
+ // does nothing
+ }
+ };
+ }
+ }
+
+ let articleService = {
+ getChildren: (article_id: number, filters: {}) => {
+ return promiseResultTemplate(null);
+ }
+ };
+
+ @Component({
+ selector: 'test-container-component',
+ template: htmlTemplate,
+ directives: [ArticleBlogComponent],
+ providers: [
+ provideEmptyObjects('Restangular'),
+ createProviderToValue('ArticleService', articleService),
+ provideFilters('truncateFilter')
+ ]
+ })
+ class BlogContainerComponent {
+ article = {
+ type: 'anyArticleType'
+ };
+ profile = {
+ name: 'profile-name'
+ };
+ }
+
+ beforeEach(() => {
+
+ // the karma preprocessor html2js transform the templates html into js files which put
+ // the templates to the templateCache into the module templates
+ // we need to load the module templates here as the template for the
+ // component Noosfero ArtileView will be load on our tests
+ angular.mock.module("templates");
+
+ providers((provide: any) => {
+ return [
+ provide('ArticleService', {
+ useValue: articleService
+ })
+ ];
+ });
+ });
+
+ it("renders the blog content", (done: Function) => {
+
+ createComponentFromClass(BlogContainerComponent).then((fixture) => {
+
+ expect(fixture.debugElement.query('div.blog').length).toEqual(1);
+
+ done();
+ });
+ });
+
+ it("verify the blog data", (done: Function) => {
+
+ let articles = [{
+ id: 1,
+ title: 'The article test'
+ }];
+
+ let result = { data: articles, headers: (name: string) => { return 1; } };
+
+ // defining a mock result to articleService.getChildren method
+ articleService.getChildren = (article_id: number, filters: {}) => {
+ return promiseResultTemplate(result);
+ };
+
+ createComponentFromClass(BlogContainerComponent).then((fixture) => {
+
+ // gets the children component of BlogContainerComponent
+ let articleBlog: BlogContainerComponent = fixture.debugElement.componentViewChildren[0].componentInstance;
+
+ // check if the component property are the provided by the mocked articleService
+ let post = {
+ id: 1,
+ title: 'The article test'
+ };
+ expect((articleBlog)["posts"][0]).toEqual(jasmine.objectContaining(post));
+ expect((articleBlog)["totalPosts"]).toEqual(1);
+
+ done();
+ });
+
+ });
+
+});
\ No newline at end of file
diff --git a/src/app/article/types/blog/blog.component.ts b/src/app/article/types/blog/blog.component.ts
new file mode 100644
index 0000000..9c0ffd7
--- /dev/null
+++ b/src/app/article/types/blog/blog.component.ts
@@ -0,0 +1,47 @@
+import {Component, Input, Inject} from "ng-forward";
+
+import {ArticleService} from "../../../../lib/ng-noosfero-api/http/article.service";
+
+/**
+ * @ngdoc controller
+ * @name ArticleBlog
+ * @description
+ * An specific {@link ArticleView} for Blog articles.
+ */
+@Component({
+ selector: "noosfero-blog",
+ templateUrl: "app/article/types/blog/blog.html"
+})
+@Inject(ArticleService)
+export class ArticleBlogComponent {
+
+ @Input() article: noosfero.Article;
+ @Input() profile: noosfero.Profile;
+
+ private posts: noosfero.Article[];
+ private perPage: number = 3;
+ private currentPage: number;
+ private totalPosts: number = 0;
+
+ constructor(private articleService: ArticleService) { }
+
+ ngOnInit() {
+ this.loadPage();
+ }
+
+ loadPage() {
+ let filters = {
+ content_type: "TinyMceArticle",
+ per_page: this.perPage,
+ page: this.currentPage
+ };
+
+ this.articleService
+ .getChildren(this.article, filters)
+ .then((result: noosfero.RestResult) => {
+ this.totalPosts = result.headers("total");
+ this.posts = result.data;
+ });
+ }
+
+}
diff --git a/src/app/article/types/blog/blog.html b/src/app/article/types/blog/blog.html
new file mode 100644
index 0000000..758a3c9
--- /dev/null
+++ b/src/app/article/types/blog/blog.html
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/app/article/types/blog/blog.scss b/src/app/article/types/blog/blog.scss
new file mode 100644
index 0000000..8d59d13
--- /dev/null
+++ b/src/app/article/types/blog/blog.scss
@@ -0,0 +1,15 @@
+.blog {
+ .blog-cover {
+ margin: -15px;
+ position: relative;
+ h3 {
+ position: absolute;
+ bottom: 0;
+ background-color: rgba(0, 0, 0, 0.4);
+ color: white;
+ padding: 10px 15px;
+ margin: 0;
+ width: 100%;
+ }
+ }
+}
diff --git a/src/app/article/types/blog/index.ts b/src/app/article/types/blog/index.ts
new file mode 100644
index 0000000..5436e7c
--- /dev/null
+++ b/src/app/article/types/blog/index.ts
@@ -0,0 +1,2 @@
+/* Module Index Entry - generated using the script npm run generate-index */
+export * from "./blog.component";
diff --git a/src/app/article/types/index.ts b/src/app/article/types/index.ts
new file mode 100644
index 0000000..4206e70
--- /dev/null
+++ b/src/app/article/types/index.ts
@@ -0,0 +1 @@
+/* Module Index Entry - generated using the script npm run generate-index */
diff --git a/src/app/cms/cms.component.spec.ts b/src/app/cms/cms.component.spec.ts
deleted file mode 100644
index f4fbf01..0000000
--- a/src/app/cms/cms.component.spec.ts
+++ /dev/null
@@ -1,56 +0,0 @@
-import {quickCreateComponent} from "../../spec/helpers";
-import {Cms} from "./cms.component";
-
-describe("Components", () => {
- describe("Cms Component", () => {
-
- let $rootScope: ng.IRootScopeService;
- let $q: ng.IQService;
- let articleServiceMock: any;
- let profileServiceMock: any;
- let $state: any;
- let profile = { id: 1 };
- let notification: any;
-
-
- beforeEach(inject((_$rootScope_: ng.IRootScopeService, _$q_: ng.IQService) => {
- $rootScope = _$rootScope_;
- $q = _$q_;
- }));
-
- beforeEach(() => {
- $state = jasmine.createSpyObj("$state", ["transitionTo"]);
- notification = jasmine.createSpyObj("notification", ["success"]);
- profileServiceMock = jasmine.createSpyObj("profileServiceMock", ["getCurrentProfile"]);
- articleServiceMock = jasmine.createSpyObj("articleServiceMock", ["createInProfile"]);
-
- let getCurrentProfileResponse = $q.defer();
- getCurrentProfileResponse.resolve(profile);
-
- let articleCreate = $q.defer();
- articleCreate.resolve({ data: { path: "path", profile: { identifier: "profile" } }});
-
- profileServiceMock.getCurrentProfile = jasmine.createSpy("getCurrentProfile").and.returnValue(getCurrentProfileResponse.promise);
- articleServiceMock.createInProfile = jasmine.createSpy("createInProfile").and.returnValue(articleCreate.promise);
- });
-
- it("create an article in the current profile when save", done => {
- let component: Cms = new Cms(articleServiceMock, profileServiceMock, $state, notification);
- component.save();
- $rootScope.$apply();
- expect(profileServiceMock.getCurrentProfile).toHaveBeenCalled();
- expect(articleServiceMock.createInProfile).toHaveBeenCalledWith(profile, component.article);
- done();
- });
-
- it("got to the new article page and display an alert when saving sucessfully", done => {
- let component: Cms = new Cms(articleServiceMock, profileServiceMock, $state, notification);
- component.save();
- $rootScope.$apply();
- expect($state.transitionTo).toHaveBeenCalledWith("main.profile.page", { page: "path", profile: "profile" });
- expect(notification.success).toHaveBeenCalled();
- done();
- });
-
- });
-});
diff --git a/src/app/cms/cms.component.ts b/src/app/cms/cms.component.ts
deleted file mode 100644
index 2ce909f..0000000
--- a/src/app/cms/cms.component.ts
+++ /dev/null
@@ -1,35 +0,0 @@
-import {StateConfig, Component, Inject, provide} from 'ng-forward';
-import {ArticleService} from "../../lib/ng-noosfero-api/http/article.service";
-import {ProfileService} from "../../lib/ng-noosfero-api/http/profile.service";
-import {Notification} from "../components/notification/notification.component";
-
-@Component({
- selector: 'cms',
- templateUrl: "app/cms/cms.html",
- providers: [
- provide('articleService', { useClass: ArticleService }),
- provide('profileService', { useClass: ProfileService }),
- provide('notification', { useClass: Notification })
- ]
-})
-@Inject(ArticleService, ProfileService, "$state", Notification)
-export class Cms {
-
- article: noosfero.Article = {};
-
- constructor(private articleService: ArticleService,
- private profileService: ProfileService,
- private $state: ng.ui.IStateService,
- private notification: Notification) { }
-
- save() {
- this.profileService.getCurrentProfile().then((profile: noosfero.Profile) => {
- return this.articleService.createInProfile(profile, this.article);
- }).then((response: noosfero.RestResult) => {
- let article = (response.data);
- this.$state.transitionTo('main.profile.page', { page: article.path, profile: article.profile.identifier });
- this.notification.success("Good job!", "Article saved!");
- });
- }
-
-}
diff --git a/src/app/cms/cms.html b/src/app/cms/cms.html
deleted file mode 100644
index 5146869..0000000
--- a/src/app/cms/cms.html
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
- Title
-
-
-
- Text
-
-
- Save
-
diff --git a/src/app/cms/index.ts b/src/app/cms/index.ts
deleted file mode 100644
index 2ee57fe..0000000
--- a/src/app/cms/index.ts
+++ /dev/null
@@ -1,2 +0,0 @@
-/* Module Index Entry - generated using the script npm run generate-index */
-export * from "./cms.component";
diff --git a/src/app/components/auth/auth_controller.spec.ts b/src/app/components/auth/auth_controller.spec.ts
deleted file mode 100644
index 2e7ec8f..0000000
--- a/src/app/components/auth/auth_controller.spec.ts
+++ /dev/null
@@ -1,33 +0,0 @@
-import {AuthController} from "./auth_controller";
-import {AuthService} from "./auth_service";
-
-describe("Controllers", () => {
-
-
- describe("AuthController", () => {
-
- it("calls authenticate on AuthService when login called", () => {
-
- // creating a Mock AuthService
- let AuthServiceMock: AuthService = jasmine.createSpyObj("AuthService", ["login"]);
-
- // pass AuthServiceMock into the constructor
- let authController = new AuthController(null, null, AuthServiceMock);
-
- // setup of authController -> set the credentials instance property
- let credentials = { username: "username", password: "password" };
-
- authController.credentials = credentials;
-
- // calls the authController login method
- authController.login();
-
- // checks if the method login of the injected AuthService has been called
- expect(AuthServiceMock.login).toHaveBeenCalledWith(credentials);
-
- });
-
-
-
- });
-});
diff --git a/src/app/components/auth/auth_controller.ts b/src/app/components/auth/auth_controller.ts
deleted file mode 100644
index 768ae63..0000000
--- a/src/app/components/auth/auth_controller.ts
+++ /dev/null
@@ -1,20 +0,0 @@
-import {AuthService} from "./auth_service";
-
-export class AuthController {
-
- static $inject = ["$log", "$stateParams", "AuthService"];
-
- constructor(
- private $log: ng.ILogService,
- private $stateParams: any,
- private AuthService: AuthService
- ) {
-
- }
-
- credentials: noosfero.Credentials;
-
- login() {
- this.AuthService.login(this.credentials);
- }
-}
diff --git a/src/app/components/auth/auth_events.ts b/src/app/components/auth/auth_events.ts
deleted file mode 100644
index 875d139..0000000
--- a/src/app/components/auth/auth_events.ts
+++ /dev/null
@@ -1,11 +0,0 @@
-export interface IAuthEvents {
- loginSuccess: string;
- loginFailed: string;
- logoutSuccess: string;
-}
-
-export const AUTH_EVENTS: IAuthEvents = {
- loginSuccess: "auth-login-success",
- loginFailed: "auth-login-failed",
- logoutSuccess: "auth-logout-success"
-};
\ No newline at end of file
diff --git a/src/app/components/auth/auth_service.spec.ts b/src/app/components/auth/auth_service.spec.ts
deleted file mode 100644
index 5b417ba..0000000
--- a/src/app/components/auth/auth_service.spec.ts
+++ /dev/null
@@ -1,81 +0,0 @@
-
-
-import {AuthService, AUTH_EVENTS} from "./";
-
-describe("Services", () => {
-
-
- describe("Auth Service", () => {
-
- let $httpBackend: ng.IHttpBackendService;
- let authService: AuthService;
- let credentials: noosfero.Credentials;
- let $rootScope: ng.IRootScopeService;
- let user: noosfero.User;
-
- beforeEach(angular.mock.module("noosferoApp", ($translateProvider: angular.translate.ITranslateProvider) => {
- $translateProvider.translations('en', {});
- }));
-
- beforeEach(inject((_$httpBackend_: ng.IHttpBackendService, _$rootScope_: ng.IRootScopeService, _AuthService_: AuthService) => {
- $httpBackend = _$httpBackend_;
- authService = _AuthService_;
- $rootScope = _$rootScope_;
-
- user = {
- id: 1,
- login: "user"
- };
- }));
-
-
- describe("Succesffull login", () => {
-
- beforeEach(() => {
- credentials = { username: "user", password: "password" };
-
- $httpBackend.expectPOST("/api/v1/login", "login=user&password=password").respond(200, { user: user });
- });
-
- it("should return loggedUser", (done) => {
- authService.login(credentials).then((loggedUser) => {
- expect(loggedUser).toBeDefined();
- done();
- });
- $httpBackend.flush();
- expect($httpBackend.verifyNoOutstandingRequest());
- });
-
-
- it("should emit event loggin successful with user logged data", () => {
-
- authService.login(credentials);
-
- let eventEmmited: boolean = false;
- $rootScope.$on(AUTH_EVENTS.loginSuccess, (event: ng.IAngularEvent, userThroughEvent: noosfero.User) => {
- eventEmmited = true;
- expect(userThroughEvent).toEqual(user);
- });
-
- $httpBackend.flush();
-
- expect(eventEmmited).toBeTruthy(AUTH_EVENTS.loginSuccess + " was not emmited!");
- });
-
- it("should return the current logged in user", () => {
- authService.login(credentials);
- $httpBackend.flush();
- let actual: noosfero.User = authService.currentUser();
- expect(actual).toEqual(user, "The returned user must be present");
- });
-
- it("should not return the current user after logout", () => {
- authService.logout();
- let actual: any = authService.currentUser();
- expect(actual).toEqual(undefined, "The returned user must not be defined");
- });
- });
-
-
- });
-});
diff --git a/src/app/components/auth/auth_service.ts b/src/app/components/auth/auth_service.ts
deleted file mode 100644
index 6b663b7..0000000
--- a/src/app/components/auth/auth_service.ts
+++ /dev/null
@@ -1,69 +0,0 @@
-import {Injectable, Inject} from "ng-forward";
-
-import {NoosferoRootScope, UserResponse} from "./../../models/interfaces";
-import {Session} from "./session";
-
-import {AUTH_EVENTS, IAuthEvents} from "./auth_events";
-
-@Injectable()
-@Inject("$q", "$http", "$rootScope", "Session", "$log", "AUTH_EVENTS")
-export class AuthService {
-
- constructor(private $q: ng.IQService,
- private $http: ng.IHttpService,
- private $rootScope: NoosferoRootScope,
- private session: Session,
- private $log: ng.ILogService,
- private auth_events: IAuthEvents) {
-
- }
-
- loginFromCookie() {
- let url: string = '/api/v1/login_from_cookie';
- return this.$http.post(url, null).then(this.loginSuccessCallback.bind(this), this.loginFailedCallback.bind(this));
- }
-
-
- private loginSuccessCallback(response: ng.IHttpPromiseCallbackArg) {
- this.$log.debug('AuthService.login [SUCCESS] response', response);
- let currentUser: noosfero.User = this.session.create(response.data);
- this.$rootScope.currentUser = currentUser;
- this.$rootScope.$broadcast(this.auth_events.loginSuccess, currentUser);
- return currentUser;
- }
-
- login(credentials: noosfero.Credentials): ng.IPromise {
- let url = '/api/v1/login';
- let encodedData = 'login=' + credentials.username + '&password=' + credentials.password;
- return this.$http.post(url, encodedData).then(this.loginSuccessCallback.bind(this), this.loginFailedCallback.bind(this));
- }
-
- private loginFailedCallback(response: ng.IHttpPromiseCallbackArg): any {
- this.$log.debug('AuthService.login [FAIL] response', response);
- this.$rootScope.$broadcast(this.auth_events.loginFailed);
- // return $q.reject(response);
- return null;
- }
-
- public logout() {
- this.session.destroy();
- this.$rootScope.currentUser = undefined;
- this.$rootScope.$broadcast(this.auth_events.logoutSuccess);
- this.$http.jsonp('/account/logout'); // FIXME logout from noosfero to sync login state
- }
-
- public isAuthenticated() {
- return !!this.session.currentUser();
- }
-
- public currentUser(): noosfero.User {
- return this.session.currentUser();
- }
-
- public isAuthorized(authorizedRoles: string | string[]) {
- if (!angular.isArray(authorizedRoles)) {
- authorizedRoles = [authorizedRoles];
- }
- return (this.isAuthenticated() && authorizedRoles.indexOf(this.session.currentUser().userRole) !== -1);
- }
-}
\ No newline at end of file
diff --git a/src/app/components/auth/index.ts b/src/app/components/auth/index.ts
deleted file mode 100644
index 39bfb1b..0000000
--- a/src/app/components/auth/index.ts
+++ /dev/null
@@ -1,5 +0,0 @@
-/* Module Index Entry - generated using the script npm run generate-index */
-export * from "./auth_controller";
-export * from "./auth_events";
-export * from "./auth_service";
-export * from "./session";
diff --git a/src/app/components/auth/login.html b/src/app/components/auth/login.html
deleted file mode 100644
index 8c01ca8..0000000
--- a/src/app/components/auth/login.html
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
diff --git a/src/app/components/auth/session.ts b/src/app/components/auth/session.ts
deleted file mode 100644
index 990a2c0..0000000
--- a/src/app/components/auth/session.ts
+++ /dev/null
@@ -1,27 +0,0 @@
-import {Injectable, Inject} from "ng-forward";
-import {UserResponse, INoosferoLocalStorage} from "./../../models/interfaces";
-
-@Injectable()
-@Inject("$localStorage", "$log")
-export class Session {
-
- constructor(private $localStorage: INoosferoLocalStorage, private $log: ng.ILogService) {
-
- }
-
- create(data: UserResponse): noosfero.User {
- this.$localStorage.currentUser = data.user;
- this.$log.debug('User session created.', this.$localStorage.currentUser);
- return this.$localStorage.currentUser;
- };
-
- destroy() {
- delete this.$localStorage.currentUser;
- this.$log.debug('User session destroyed.');
- };
-
- currentUser(): noosfero.User {
- return this.$localStorage.currentUser;
- };
-
-}
\ No newline at end of file
diff --git a/src/app/components/auth/session_spec.ts b/src/app/components/auth/session_spec.ts
deleted file mode 100644
index 7413fc6..0000000
--- a/src/app/components/auth/session_spec.ts
+++ /dev/null
@@ -1,49 +0,0 @@
-import {Component} from "ng-forward";
-import {Session} from "./";
-import {fixtures, createComponentFromClass, createProviderToValue} from "./../../../spec/helpers";
-import {UserResponse, INoosferoLocalStorage} from "./../../models/interfaces";
-
-
-describe("Services", () => {
-
-
- describe("Session Service", () => {
-
- let $localStorage: INoosferoLocalStorage = null;
- let $log: any;
-
- beforeEach(() => {
- $localStorage = { currentUser: null };
- $log = jasmine.createSpyObj('$log', ['debug']);
- });
-
- it("method 'create()' saves the current user on $localstorage service", () => {
- let session = new Session($localStorage, $log);
- let userResponse = {
- user: fixtures.user
- };
- session.create(userResponse);
- expect($localStorage.currentUser).toEqual(userResponse.user);
- });
-
- it("method 'destroy()' clean the currentUser on $localstorage", () => {
- let session = new Session($localStorage, $log);
- let userResponse = {
- user: fixtures.user
- };
- $localStorage.currentUser = fixtures.user;
- session.destroy();
- expect($localStorage.currentUser).toBeUndefined();
- });
-
- it("method 'currentUser()' returns the user recorded on $localstorage service", () => {
- let session = new Session($localStorage, $log);
- let userResponse = {
- user: fixtures.user
- };
- $localStorage.currentUser = fixtures.user;
- expect(session.currentUser()).toEqual($localStorage.currentUser);
- });
- });
-
-});
\ No newline at end of file
diff --git a/src/app/components/index.ts b/src/app/components/index.ts
deleted file mode 100644
index 4206e70..0000000
--- a/src/app/components/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-/* Module Index Entry - generated using the script npm run generate-index */
diff --git a/src/app/components/language-selector/language-selector.component.ts b/src/app/components/language-selector/language-selector.component.ts
deleted file mode 100644
index 502444d..0000000
--- a/src/app/components/language-selector/language-selector.component.ts
+++ /dev/null
@@ -1,24 +0,0 @@
-import {Component, Inject} from "ng-forward";
-import {TranslatorService} from "../translator/translator.service";
-
-@Component({
- selector: "language-selector",
- templateUrl: "app/components/language-selector/language-selector.html"
-})
-@Inject(TranslatorService)
-export class LanguageSelector {
-
- constructor(private translatorService: TranslatorService) { }
-
- currentLanguage() {
- return this.translatorService.currentLanguage();
- }
-
- changeLanguage(language: string) {
- this.translatorService.changeLanguage(language);
- }
-
- availableLanguages() {
- return this.translatorService.availableLanguages;
- }
-}
diff --git a/src/app/components/language-selector/language-selector.html b/src/app/components/language-selector/language-selector.html
deleted file mode 100644
index 9499df5..0000000
--- a/src/app/components/language-selector/language-selector.html
+++ /dev/null
@@ -1,13 +0,0 @@
-
diff --git a/src/app/components/navbar/index.ts b/src/app/components/navbar/index.ts
deleted file mode 100644
index dd56b10..0000000
--- a/src/app/components/navbar/index.ts
+++ /dev/null
@@ -1,2 +0,0 @@
-/* Module Index Entry - generated using the script npm run generate-index */
-export * from "./navbar";
diff --git a/src/app/components/navbar/navbar.directive.spec.js b/src/app/components/navbar/navbar.directive.spec.js
deleted file mode 100644
index 2f89fad..0000000
--- a/src/app/components/navbar/navbar.directive.spec.js
+++ /dev/null
@@ -1,45 +0,0 @@
-(function() {
- 'use strict';
-
- describe('directive navbar', function() {
- var vm;
- var el;
- var AUTH_EVENTS;
- var $state;
-
- beforeEach(module('angular'));
- beforeEach(inject(function($compile, $rootScope, $httpBackend, _AUTH_EVENTS_, _$state_) {
- $state = _$state_;
- AUTH_EVENTS = _AUTH_EVENTS_;
- $httpBackend.when('POST','/api/v1/login_from_cookie').respond({});
-
- el = angular.element(' ');
-
- $compile(el)($rootScope.$new());
- $rootScope.$digest();
- vm = el.isolateScope().vm;
- }));
-
- it('should be compiled', function() {
- expect(el.html()).not.toEqual(null);
- });
-
- it('should have isolate scope object with instanciate members', function() {
- expect(vm).toEqual(jasmine.any(Object));
- expect(vm.currentUser).toEqual(undefined);
- });
-
- it('should reload current state after login', function() {
- spyOn($state, 'go');
- el.isolateScope().$broadcast(AUTH_EVENTS.loginSuccess, {});
- expect($state.go).toHaveBeenCalled();
- });
-
- it('should open login when not logged in', function() {
- spyOn(vm, 'openLogin');
- vm.activate();
- expect(vm.openLogin).toHaveBeenCalled();
- });
-
- });
-})();
diff --git a/src/app/components/navbar/navbar.html b/src/app/components/navbar/navbar.html
deleted file mode 100644
index ed5742f..0000000
--- a/src/app/components/navbar/navbar.html
+++ /dev/null
@@ -1,49 +0,0 @@
-
-
-
diff --git a/src/app/components/navbar/navbar.scss b/src/app/components/navbar/navbar.scss
deleted file mode 100644
index 5809fab..0000000
--- a/src/app/components/navbar/navbar.scss
+++ /dev/null
@@ -1,31 +0,0 @@
-.navbar {
-
- .container-fluid {
- padding-right: 12%;
- padding-left: 12%;
- @media (max-width: 978px) {
- padding-right: 2%;
- padding-left: 2%;
- }
-
- .navbar-brand {
- .noosfero-logo img {
- height: 35px;
- }
- }
-
- .navbar-nav {
- .profile-menu .profile-image {
- img {
- height: 30px;
- width: 30px;
- display: inline-block;
- @extend .img-circle;
- }
- i {
- font-size: 1.7em;
- }
- }
- }
- }
-}
diff --git a/src/app/components/navbar/navbar.spec.ts b/src/app/components/navbar/navbar.spec.ts
deleted file mode 100644
index 88b8cd2..0000000
--- a/src/app/components/navbar/navbar.spec.ts
+++ /dev/null
@@ -1,187 +0,0 @@
-import * as helpers from "./../../../spec/helpers";
-import {Navbar} from "./navbar";
-import {AUTH_EVENTS} from "./../auth";
-import {Injectable, Provider, provide} from "ng-forward";
-
-import {ComponentFixture} from 'ng-forward/cjs/testing/test-component-builder';
-
-import {Session, AuthService, AuthController, IAuthEvents} from "./../auth";
-
-
-describe("Components", () => {
-
- describe("Navbar Component", () => {
-
- let user: noosfero.User = null;
- let scope: any;
- let $rootScope: ng.IRootScopeService;
-
- let modalInstance: any;
- let $modal: any;
- let authService: any;
- let stateService: any;
- let sessionService: Session;
-
- let provideFunc = provide;
-
- // before Each -> loading mocks on locals variables
- beforeEach(() => {
- user = {
- id: 1,
- login: "user"
- };
- scope = helpers.mocks.scopeWithEvents;
- modalInstance = helpers.mocks.modalInstance;
- $modal = helpers.mocks.$modal;
- authService = helpers.mocks.authService;
- stateService = jasmine.createSpyObj("$state", ["go"]);
- sessionService = helpers.mocks.sessionWithCurrentUser(user);
- });
-
-
- // loading the templates
- beforeEach(angular.mock.module("templates"));
-
-
- // this function allow build the fixture of the container component
- // and is reused in each test
- // The main idea behing not prebuild it on a general beforeEach block is
- // to allow tests configure the mock services accordilly their own needs
- let buildComponent = (): Promise => {
- return helpers.quickCreateComponent({
- providers: [
- provide('$modal', {
- useValue: $modal
- }),
- provide('AuthService', {
- useValue: authService
- }),
- helpers.provideEmptyObjects('moment'),
- provide('$state', {
- useValue: stateService
- }),
- provide("$scope", {
- useValue: scope
- }),
- provide('Session', {
- useValue: sessionService
- }),
- provide('AUTH_EVENTS', {
- useValue: {
- AUTH_EVENTS
- }
- }),
- provide('TranslatorService', {
- useValue: helpers.mocks.translatorService
- })
- ].concat(helpers.provideFilters("translateFilter")),
- directives: [Navbar],
- template: ' '
- });
- };
-
-
- it('should get the loggedIn user', (done: Function) => {
- buildComponent().then((fixture: ComponentFixture) => {
- let navbarInstance: Navbar = fixture.debugElement.componentViewChildren[0].componentInstance;
- expect(navbarInstance).toBeDefined();
- expect(navbarInstance["currentUser"]).toEqual(user);
- done();
- });
- });
-
- it('should open on click', (done: Function) => {
- spyOn($modal, "open");
- buildComponent().then((fixture: ComponentFixture) => {
- let navbarComp: Navbar = fixture.debugElement.componentViewChildren[0].componentInstance;
- navbarComp.openLogin();
- expect($modal.open).toHaveBeenCalled();
- expect($modal.open).toHaveBeenCalledWith({
- templateUrl: 'app/components/auth/login.html',
- controller: AuthController,
- controllerAs: 'vm',
- bindToController: true
- });
- done();
- });
- });
-
- it('should logout', (done: Function) => {
- buildComponent().then((fixture: ComponentFixture) => {
- let navbarComp: Navbar = fixture.debugElement.componentViewChildren[0].componentInstance;
- spyOn(authService, "logout");
- try {
- navbarComp.logout();
- expect(authService.logout).toHaveBeenCalled();
- done();
- } catch (e) {
- console.error(e);
- fail(e.message);
- done();
- }
- });
- });
-
-
- it('should not activate user when logged in', (done: Function) => {
- buildComponent().then((fixture: ComponentFixture) => {
- let navbarComp: Navbar = fixture.debugElement.componentViewChildren[0].componentInstance;
- spyOn(navbarComp, "openLogin");
- navbarComp.activate();
- expect((navbarComp.openLogin).calls.count()).toBe(0);
- done();
- });
- });
-
- it('should activate when user not logged in', (done: Function) => {
- spyOn(sessionService, 'currentUser').and.returnValue(null);
- buildComponent().then((fixture: ComponentFixture) => {
- let navbarComp: Navbar = fixture.debugElement.componentViewChildren[0].componentInstance;
- spyOn(navbarComp, "openLogin");
- navbarComp.activate();
- expect(navbarComp.openLogin).toHaveBeenCalled();
- done();
- });
- });
-
-
- it('closes the modal after login', (done: Function) => {
- modalInstance = jasmine.createSpyObj("modalInstance", ["close"]);
- modalInstance.close = jasmine.createSpy("close");
-
- $modal.open = () => {
- return modalInstance;
- };
-
- buildComponent().then((fixture: ComponentFixture) => {
- let navbarComp: Navbar = fixture.debugElement.componentViewChildren[0].componentInstance;
- let localScope: ng.IScope = navbarComp["$scope"];
-
- navbarComp.openLogin();
- localScope.$emit(AUTH_EVENTS.loginSuccess);
- expect(modalInstance.close).toHaveBeenCalled();
- done();
- });
- });
-
- it('updates current user on logout', (done: Function) => {
- buildComponent().then((fixture: ComponentFixture) => {
- let navbarComp: Navbar = fixture.debugElement.componentViewChildren[0].componentInstance;
- let localScope: ng.IScope = navbarComp["$scope"];
-
- // init navbar currentUser with some user
- navbarComp["currentUser"] = user;
-
- // changes the current User to return null,
- // and emmit the 'logoutSuccess' event
- // just what happens when user logsout
- sessionService.currentUser = () => { return null; };
- localScope.$emit(AUTH_EVENTS.logoutSuccess);
- expect(navbarComp["currentUser"]).toBeNull();
- done();
- });
- });
-
-
- });
-});
diff --git a/src/app/components/navbar/navbar.ts b/src/app/components/navbar/navbar.ts
deleted file mode 100644
index e466a76..0000000
--- a/src/app/components/navbar/navbar.ts
+++ /dev/null
@@ -1,66 +0,0 @@
-import {Component, Inject} from "ng-forward";
-import {LanguageSelector} from "../language-selector/language-selector.component";
-
-
-import {Session, AuthService, AuthController, IAuthEvents, AUTH_EVENTS} from "./../auth";
-
-@Component({
- selector: "acme-navbar",
- templateUrl: "app/components/navbar/navbar.html",
- directives: [LanguageSelector],
- providers: [AuthService, Session]
-})
-@Inject("$modal", AuthService, "Session", "$scope", "$state")
-export class Navbar {
-
- private currentUser: noosfero.User;
- private modalInstance: any = null;
- /**
- *
- */
- constructor(
- private $modal: any,
- private authService: AuthService,
- private session: Session,
- private $scope: ng.IScope,
- private $state: ng.ui.IStateService
- ) {
- this.currentUser = this.session.currentUser();
-
- this.$scope.$on(AUTH_EVENTS.loginSuccess, () => {
- if (this.modalInstance) {
- this.modalInstance.close();
- this.modalInstance = null;
- }
-
- this.$state.go(this.$state.current, {}, { reload: true }); // TODO move to auth
- });
-
- this.$scope.$on(AUTH_EVENTS.logoutSuccess, () => {
- this.currentUser = this.session.currentUser();
- });
- }
-
- openLogin() {
- this.modalInstance = this.$modal.open({
- templateUrl: 'app/components/auth/login.html',
- controller: AuthController,
- controllerAs: 'vm',
- bindToController: true
- });
- };
-
- logout() {
- this.authService.logout();
- this.$state.go(this.$state.current, {}, { reload: true }); // TODO move to auth
- };
-
-
-
- activate() {
- if (!this.currentUser) {
- this.openLogin();
- }
- }
-
-}
diff --git a/src/app/components/noosfero-activities/activities.component.spec.ts b/src/app/components/noosfero-activities/activities.component.spec.ts
deleted file mode 100644
index 5b4cd6b..0000000
--- a/src/app/components/noosfero-activities/activities.component.spec.ts
+++ /dev/null
@@ -1,36 +0,0 @@
-import {TestComponentBuilder} from 'ng-forward/cjs/testing/test-component-builder';
-import {Pipe, Input, provide, Component} from 'ng-forward';
-import {provideFilters} from '../../../spec/helpers';
-
-import {NoosferoActivities} from './activities.component';
-
-const tcb = new TestComponentBuilder();
-
-const htmlTemplate: string = ' ';
-
-
-describe("Components", () => {
-
- describe("Noosfero Activities", () => {
-
- beforeEach(angular.mock.module("templates"));
-
- @Component({
- selector: 'test-container-component',
- template: htmlTemplate,
- directives: [NoosferoActivities],
- providers: provideFilters("truncateFilter", "stripTagsFilter", "translateFilter")
- })
- class BlockContainerComponent {
- activities = [{ name: "activity1", verb: "create_article" }, { name: "activity2", verb: "create_article" }];
- }
-
- it("render a noosfero activity tag for each activity", done => {
- tcb.createAsync(BlockContainerComponent).then(fixture => {
- expect(fixture.debugElement.queryAll("noosfero-activity").length).toEqual(2);
- done();
- });
- });
- });
-
-});
diff --git a/src/app/components/noosfero-activities/activities.component.ts b/src/app/components/noosfero-activities/activities.component.ts
deleted file mode 100644
index 596fa40..0000000
--- a/src/app/components/noosfero-activities/activities.component.ts
+++ /dev/null
@@ -1,27 +0,0 @@
-import {Component, Input} from "ng-forward";
-import {NoosferoActivity} from "./activity/activity.component";
-
-/**
- * @ngdoc controller
- * @name NoosferoActivities
- * @description
- * The controller responsible to retreive profile activities.
- */
-
-@Component({
- selector: "noosfero-activities",
- templateUrl: 'app/components/noosfero-activities/activities.html',
- directives: [NoosferoActivity]
-})
-export class NoosferoActivities {
-
- /**
- * @ngdoc property
- * @propertyOf NoosferoActivities
- * @name activities
- * @returns {Activity[]} An array of {@link Activity}.
- */
- @Input() activities: noosfero.Activity[];
-
-
-}
diff --git a/src/app/components/noosfero-activities/activities.html b/src/app/components/noosfero-activities/activities.html
deleted file mode 100644
index f99e3e3..0000000
--- a/src/app/components/noosfero-activities/activities.html
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
-
-
-
diff --git a/src/app/components/noosfero-activities/activities.scss b/src/app/components/noosfero-activities/activities.scss
deleted file mode 100644
index 88982c9..0000000
--- a/src/app/components/noosfero-activities/activities.scss
+++ /dev/null
@@ -1,11 +0,0 @@
-.comma-separated {
- .separated-item {
- &:after {
- content: ", ";
- margin-left: -3px;
- }
- &:last-child:after {
- content: "";
- }
- }
-}
diff --git a/src/app/components/noosfero-activities/activity/activity.component.spec.ts b/src/app/components/noosfero-activities/activity/activity.component.spec.ts
deleted file mode 100644
index 6654750..0000000
--- a/src/app/components/noosfero-activities/activity/activity.component.spec.ts
+++ /dev/null
@@ -1,38 +0,0 @@
-import {TestComponentBuilder} from 'ng-forward/cjs/testing/test-component-builder';
-import {Pipe, Input, provide, Component} from 'ng-forward';
-import {provideFilters} from '../../../../spec/helpers';
-
-import {NoosferoActivity} from './activity.component';
-
-const tcb = new TestComponentBuilder();
-
-const htmlTemplate: string = ' ';
-
-
-describe("Components", () => {
-
- describe("Noosfero Activity", () => {
-
- beforeEach(angular.mock.module("templates"));
-
- @Component({
- selector: 'test-container-component',
- template: htmlTemplate,
- directives: [NoosferoActivity],
- providers: provideFilters("truncateFilter", "stripTagsFilter", "translateFilter")
- })
- class BlockContainerComponent {
- activity = { name: "activity1", verb: "create_article" };
- }
-
- it("render the specific template for an activity verb", done => {
- tcb.createAsync(BlockContainerComponent).then(fixture => {
- let component: NoosferoActivity = fixture.debugElement.componentViewChildren[0].componentInstance;
- expect(component.getActivityTemplate()).toEqual('app/components/noosfero-activities/activity/create_article.html');
- expect(fixture.debugElement.queryAll(".activity.create_article").length).toEqual(1);
- done();
- });
- });
- });
-
-});
diff --git a/src/app/components/noosfero-activities/activity/activity.component.ts b/src/app/components/noosfero-activities/activity/activity.component.ts
deleted file mode 100644
index 6876405..0000000
--- a/src/app/components/noosfero-activities/activity/activity.component.ts
+++ /dev/null
@@ -1,15 +0,0 @@
-import {Component, Input} from "ng-forward";
-
-@Component({
- selector: "noosfero-activity",
- templateUrl: 'app/components/noosfero-activities/activity/activity.html'
-})
-export class NoosferoActivity {
-
- @Input() activity: noosfero.Activity;
-
- getActivityTemplate() {
- return 'app/components/noosfero-activities/activity/' + this.activity.verb + '.html';
- }
-
-}
diff --git a/src/app/components/noosfero-activities/activity/activity.html b/src/app/components/noosfero-activities/activity/activity.html
deleted file mode 100644
index 0bcc9b7..0000000
--- a/src/app/components/noosfero-activities/activity/activity.html
+++ /dev/null
@@ -1,3 +0,0 @@
-
-
-
diff --git a/src/app/components/noosfero-activities/activity/add_member_in_community.html b/src/app/components/noosfero-activities/activity/add_member_in_community.html
deleted file mode 100644
index b97512f..0000000
--- a/src/app/components/noosfero-activities/activity/add_member_in_community.html
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-
-
-
-
-
- {{"activities.add_member_in_community.description" | translate}}
-
-
-
-
-
diff --git a/src/app/components/noosfero-activities/activity/create_article.html b/src/app/components/noosfero-activities/activity/create_article.html
deleted file mode 100644
index 791ef13..0000000
--- a/src/app/components/noosfero-activities/activity/create_article.html
+++ /dev/null
@@ -1,26 +0,0 @@
-
-
-
-
-
-
-
- {{"activities.create_article.description" | translate}}
-
-
-
-
-
-
-
-
diff --git a/src/app/components/noosfero-activities/activity/index.ts b/src/app/components/noosfero-activities/activity/index.ts
deleted file mode 100644
index 4206e70..0000000
--- a/src/app/components/noosfero-activities/activity/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-/* Module Index Entry - generated using the script npm run generate-index */
diff --git a/src/app/components/noosfero-activities/activity/new_friendship.html b/src/app/components/noosfero-activities/activity/new_friendship.html
deleted file mode 100644
index c19d66d..0000000
--- a/src/app/components/noosfero-activities/activity/new_friendship.html
+++ /dev/null
@@ -1,18 +0,0 @@
-
-
-
-
-
-
-
- {{"activities.new_friendship.description" | translate:{friends: ctrl.activity.params.friend_name.length}:"messageformat" }}
-
-
-
-
-
-
-
-
-
-
diff --git a/src/app/components/noosfero-activities/index.ts b/src/app/components/noosfero-activities/index.ts
deleted file mode 100644
index 4206e70..0000000
--- a/src/app/components/noosfero-activities/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-/* Module Index Entry - generated using the script npm run generate-index */
diff --git a/src/app/components/noosfero-articles/article/article.html b/src/app/components/noosfero-articles/article/article.html
deleted file mode 100644
index 0a94109..0000000
--- a/src/app/components/noosfero-articles/article/article.html
+++ /dev/null
@@ -1,23 +0,0 @@
-
diff --git a/src/app/components/noosfero-articles/article/article.scss b/src/app/components/noosfero-articles/article/article.scss
deleted file mode 100644
index 59b91e2..0000000
--- a/src/app/components/noosfero-articles/article/article.scss
+++ /dev/null
@@ -1,17 +0,0 @@
-.article {
- .page-info {
- .author {
- a {
- color: #b4bcc2;
- }
- }
- }
-
- .page-header {
- margin-bottom: 5px;
- }
-
- .sub-header {
- margin-bottom: 20px;
- }
-}
diff --git a/src/app/components/noosfero-articles/article/article_view.spec.ts b/src/app/components/noosfero-articles/article/article_view.spec.ts
deleted file mode 100644
index 35d1925..0000000
--- a/src/app/components/noosfero-articles/article/article_view.spec.ts
+++ /dev/null
@@ -1,108 +0,0 @@
-
-import {Input, provide, Component} from 'ng-forward';
-import {ArticleView, ArticleDefaultView} from './article_view';
-
-import {createComponentFromClass, quickCreateComponent} from "../../../../spec/helpers";
-
-// this htmlTemplate will be re-used between the container components in this spec file
-const htmlTemplate: string = ' ';
-
-
-describe("Components", () => {
-
- describe("ArticleView Component", () => {
-
- // the karma preprocessor html2js transform the templates html into js files which put
- // the templates to the templateCache into the module templates
- // we need to load the module templates here as the template for the
- // component Noosfero ArtileView will be load on our tests
- beforeEach(angular.mock.module("templates"));
-
- it("renders the default component when no specific component is found", (done: Function) => {
- // Creating a container component (ArticleContainerComponent) to include
- // the component under test (ArticleView)
- @Component({ selector: 'test-container-component', template: htmlTemplate, directives: [ArticleView] })
- class ArticleContainerComponent {
- article = { type: 'anyArticleType' };
- profile = { name: 'profile-name' };
- constructor() {
- }
- }
-
- createComponentFromClass(ArticleContainerComponent).then((fixture) => {
- // and here we can inspect and run the test assertions
-
- // gets the children component of ArticleContainerComponent
- let articleView: ArticleView = fixture.debugElement.componentViewChildren[0].componentInstance;
-
- // and checks if the article View rendered was the Default Article View
- expect(articleView.constructor.prototype).toEqual(ArticleDefaultView.prototype);
-
- // done needs to be called (it isn't really needed, as we can read in
- // here (https://github.com/ngUpgraders/ng-forward/blob/master/API.md#createasync)
- // because createAsync in ng-forward is not really async, but as the intention
- // here is write tests in angular 2 ways, this is recommended
- done();
- });
-
- });
-
- it("receives the article and profile as inputs", (done: Function) => {
-
- // Creating a container component (ArticleContainerComponent) to include
- // the component under test (ArticleView)
- @Component({ selector: 'test-container-component', template: htmlTemplate, directives: [ArticleView] })
- class ArticleContainerComponent {
- article = { type: 'anyArticleType' };
- profile = { name: 'profile-name' };
- constructor() {
- }
- }
-
- // uses the TestComponentBuilder instance to initialize the component
- createComponentFromClass(ArticleContainerComponent).then((fixture) => {
- // and here we can inspect and run the test assertions
- let articleView: ArticleView = fixture.debugElement.componentViewChildren[0].componentInstance;
-
- // assure the article object inside the ArticleView matches
- // the provided through the parent component
- expect(articleView.article.type).toEqual("anyArticleType");
- expect(articleView.profile.name).toEqual("profile-name");
-
- // done needs to be called (it isn't really needed, as we can read in
- // here (https://github.com/ngUpgraders/ng-forward/blob/master/API.md#createasync)
- // because createAsync in ng-forward is not really async, but as the intention
- // here is write tests in angular 2 ways, this is recommended
- done();
- });
- });
-
-
- it("renders a article view which matches to the article type", done => {
- // NoosferoTinyMceArticle component created to check if it will be used
- // when a article with type 'TinyMceArticle' is provided to the noosfero-article (ArticleView)
- // *** Important *** - the selector is what ng-forward uses to define the name of the directive provider
- @Component({ selector: 'noosfero-tiny-mce-article', template: "TinyMceArticle " })
- class TinyMceArticleView {
- @Input() article: any;
- @Input() profile: any;
- }
-
- // Creating a container component (ArticleContainerComponent) to include our NoosferoTinyMceArticle
- @Component({ selector: 'test-container-component', template: htmlTemplate, directives: [ArticleView, TinyMceArticleView] })
- class CustomArticleType {
- article = { type: 'TinyMceArticle' };
- profile = { name: 'profile-name' };
- constructor() {
- }
- }
- createComponentFromClass(CustomArticleType).then(fixture => {
- let myComponent: CustomArticleType = fixture.componentInstance;
- expect(myComponent.article.type).toEqual("TinyMceArticle");
- expect(fixture.debugElement.componentViewChildren[0].text()).toEqual("TinyMceArticle");
- done();
- });
- });
-
- });
-});
\ No newline at end of file
diff --git a/src/app/components/noosfero-articles/article/article_view.ts b/src/app/components/noosfero-articles/article/article_view.ts
deleted file mode 100644
index 0ef460a..0000000
--- a/src/app/components/noosfero-articles/article/article_view.ts
+++ /dev/null
@@ -1,57 +0,0 @@
-import { bundle, Input, Inject, Component, Directive } from 'ng-forward';
-import {ArticleBlog} from "../blog/blog.component";
-
-/**
- * @ngdoc controller
- * @name ArticleDefaultView
- * @description
- * A default view for Noosfero Articles. If the specific article view is
- * not implemented, then this view is used.
- */
-@Component({
- selector: 'noosfero-default-article',
- templateUrl: 'app/components/noosfero-articles/article/article.html'
-})
-export class ArticleDefaultView {
-
- @Input() article: noosfero.Article;
- @Input() profile: noosfero.Profile;
-
-}
-
-/**
- * @ngdoc controller
- * @name ArticleView
- * @description
- * A dynamic view for articles. It uses the article type to replace
- * the default template with the custom article directive.
- */
-@Component({
- selector: 'noosfero-article',
- template: 'not-used',
- directives: [ArticleDefaultView, ArticleBlog]
-})
-@Inject("$element", "$scope", "$injector", "$compile")
-export class ArticleView {
-
- @Input() article: noosfero.Article;
- @Input() profile: noosfero.Profile;
- directiveName: string;
-
- ngOnInit() {
- let specificDirective = 'noosfero' + this.article.type;
- this.directiveName = "noosfero-default-article";
- if (this.$injector.has(specificDirective + 'Directive')) {
- this.directiveName = specificDirective.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
- }
- this.$element.replaceWith(this.$compile('<' + this.directiveName + ' [article]="ctrl.article" [profile]="ctrl.profile">' + this.directiveName + '>')(this.$scope));
- }
-
- constructor(
- private $element: any,
- private $scope: ng.IScope,
- private $injector: ng.auto.IInjectorService,
- private $compile: ng.ICompileService) {
-
- }
-}
diff --git a/src/app/components/noosfero-articles/article/index.ts b/src/app/components/noosfero-articles/article/index.ts
deleted file mode 100644
index deea325..0000000
--- a/src/app/components/noosfero-articles/article/index.ts
+++ /dev/null
@@ -1,2 +0,0 @@
-/* Module Index Entry - generated using the script npm run generate-index */
-export * from "./article_view";
diff --git a/src/app/components/noosfero-articles/blog/blog.component.spec.ts b/src/app/components/noosfero-articles/blog/blog.component.spec.ts
deleted file mode 100644
index 04721d4..0000000
--- a/src/app/components/noosfero-articles/blog/blog.component.spec.ts
+++ /dev/null
@@ -1,129 +0,0 @@
-import {
-providers
-} from 'ng-forward/cjs/testing/providers';
-
-import {
-Input,
-Component
-} from 'ng-forward';
-import {
-ArticleBlog
-} from './blog.component';
-
-import {
-createComponentFromClass,
-quickCreateComponent,
-provideEmptyObjects,
-createProviderToValue,
-provideFilters
-} from "../../../../spec/helpers.ts";
-
-// this htmlTemplate will be re-used between the container components in this spec file
-const htmlTemplate: string = ' ';
-
-describe("Blog Component", () => {
-
- function promiseResultTemplate(response?: {}) {
- let thenFuncEmpty = (func: Function) => {
- // does nothing
- };
- if (response) {
- return {
- then: (func: (response: any) => void) => {
- func(response);
- }
- };
- } else {
- return {
- then: (func: (response: any) => void) => {
- // does nothing
- }
- };
- }
- }
-
- let articleService = {
- getChildren: (article_id: number, filters: {}) => {
- return promiseResultTemplate(null);
- }
- };
-
- @Component({
- selector: 'test-container-component',
- template: htmlTemplate,
- directives: [ArticleBlog],
- providers: [
- provideEmptyObjects('Restangular'),
- createProviderToValue('ArticleService', articleService),
- provideFilters('truncateFilter')
- ]
- })
- class BlogContainerComponent {
- article = {
- type: 'anyArticleType'
- };
- profile = {
- name: 'profile-name'
- };
- }
-
- beforeEach(() => {
-
- // the karma preprocessor html2js transform the templates html into js files which put
- // the templates to the templateCache into the module templates
- // we need to load the module templates here as the template for the
- // component Noosfero ArtileView will be load on our tests
- angular.mock.module("templates");
-
- providers((provide: any) => {
- return [
- provide('ArticleService', {
- useValue: articleService
- })
- ];
- });
- });
-
- it("renders the blog content", (done: Function) => {
-
- createComponentFromClass(BlogContainerComponent).then((fixture) => {
-
- expect(fixture.debugElement.query('div.blog').length).toEqual(1);
-
- done();
- });
- });
-
- it("verify the blog data", (done: Function) => {
-
- let articles = [{
- id: 1,
- title: 'The article test'
- }];
-
- let result = { data: articles, headers: (name: string) => { return 1; } };
-
- // defining a mock result to articleService.getChildren method
- articleService.getChildren = (article_id: number, filters: {}) => {
- return promiseResultTemplate(result);
- };
-
- createComponentFromClass(BlogContainerComponent).then((fixture) => {
-
- // gets the children component of BlogContainerComponent
- let articleBlog: BlogContainerComponent = fixture.debugElement.componentViewChildren[0].componentInstance;
-
- // check if the component property are the provided by the mocked articleService
- let post = {
- id: 1,
- title: 'The article test'
- };
- expect((articleBlog)["posts"][0]).toEqual(jasmine.objectContaining(post));
- expect((articleBlog)["totalPosts"]).toEqual(1);
-
- done();
- });
-
- });
-
-});
\ No newline at end of file
diff --git a/src/app/components/noosfero-articles/blog/blog.component.ts b/src/app/components/noosfero-articles/blog/blog.component.ts
deleted file mode 100644
index 2c4e9c2..0000000
--- a/src/app/components/noosfero-articles/blog/blog.component.ts
+++ /dev/null
@@ -1,47 +0,0 @@
-import {Component, Input, Inject} from "ng-forward";
-
-import {ArticleService} from "../../../../lib/ng-noosfero-api/http/article.service";
-
-/**
- * @ngdoc controller
- * @name ArticleBlog
- * @description
- * An specific {@link ArticleView} for Blog articles.
- */
-@Component({
- selector: "noosfero-blog",
- templateUrl: "app/components/noosfero-articles/blog/blog.html"
-})
-@Inject(ArticleService)
-export class ArticleBlog {
-
- @Input() article: noosfero.Article;
- @Input() profile: noosfero.Profile;
-
- private posts: noosfero.Article[];
- private perPage: number = 3;
- private currentPage: number;
- private totalPosts: number = 0;
-
- constructor(private articleService: ArticleService) { }
-
- ngOnInit() {
- this.loadPage();
- }
-
- loadPage() {
- let filters = {
- content_type: "TinyMceArticle",
- per_page: this.perPage,
- page: this.currentPage
- };
-
- this.articleService
- .getChildren(this.article, filters)
- .then((result: noosfero.RestResult) => {
- this.totalPosts = result.headers("total");
- this.posts = result.data;
- });
- }
-
-}
diff --git a/src/app/components/noosfero-articles/blog/blog.html b/src/app/components/noosfero-articles/blog/blog.html
deleted file mode 100644
index 758a3c9..0000000
--- a/src/app/components/noosfero-articles/blog/blog.html
+++ /dev/null
@@ -1,24 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/app/components/noosfero-articles/blog/blog.scss b/src/app/components/noosfero-articles/blog/blog.scss
deleted file mode 100644
index 8d59d13..0000000
--- a/src/app/components/noosfero-articles/blog/blog.scss
+++ /dev/null
@@ -1,15 +0,0 @@
-.blog {
- .blog-cover {
- margin: -15px;
- position: relative;
- h3 {
- position: absolute;
- bottom: 0;
- background-color: rgba(0, 0, 0, 0.4);
- color: white;
- padding: 10px 15px;
- margin: 0;
- width: 100%;
- }
- }
-}
diff --git a/src/app/components/noosfero-articles/blog/index.ts b/src/app/components/noosfero-articles/blog/index.ts
deleted file mode 100644
index 5436e7c..0000000
--- a/src/app/components/noosfero-articles/blog/index.ts
+++ /dev/null
@@ -1,2 +0,0 @@
-/* Module Index Entry - generated using the script npm run generate-index */
-export * from "./blog.component";
diff --git a/src/app/components/noosfero-articles/index.ts b/src/app/components/noosfero-articles/index.ts
deleted file mode 100644
index 4206e70..0000000
--- a/src/app/components/noosfero-articles/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-/* Module Index Entry - generated using the script npm run generate-index */
diff --git a/src/app/components/noosfero-blocks/block.component.spec.ts b/src/app/components/noosfero-blocks/block.component.spec.ts
deleted file mode 100644
index 842ae01..0000000
--- a/src/app/components/noosfero-blocks/block.component.spec.ts
+++ /dev/null
@@ -1,91 +0,0 @@
-import {TestComponentBuilder} from 'ng-forward/cjs/testing/test-component-builder';
-import {Input, provide, Component} from 'ng-forward';
-
-import {Block} from './block.component';
-
-const tcb = new TestComponentBuilder();
-
-const htmlTemplate: string = ' ';
-
-describe("Components", () => {
- describe("Block Component", () => {
-
- // the karma preprocessor html2js transform the templates html into js files which put
- // the templates to the templateCache into the module templates
- // we need to load the module templates here as the template for the
- // component Block will be load on our tests
- beforeEach(angular.mock.module("templates"));
-
- it("receives the block and the owner as inputs", done => {
-
- // Creating a container component (BlockContainerComponent) to include
- // the component under test (Block)
- @Component({ selector: 'test-container-component', template: htmlTemplate, directives: [Block] })
- class BlockContainerComponent {
- block = { type: 'Block' };
- owner = { name: 'profile-name' };
- constructor() {
- }
- }
-
- // uses the TestComponentBuilder instance to initialize the component
- tcb
- .createAsync(BlockContainerComponent).then(fixture => {
- // and here we can inspect and run the test assertions
- let myComponent: Block = fixture.componentInstance;
-
- // assure the block object inside the Block matches
- // the provided through the parent component
- expect(myComponent.block.type).toEqual("Block");
- expect(myComponent.owner.name).toEqual("profile-name");
- done();
- });
- });
-
-
- it("renders a component which matches to the block type", done => {
- // CustomBlock component created to check if it will be used
- // when a block with type 'CustomBlock' is provided to the noosfero-block (Block)
- // *** Important *** - the selector is what ng-forward uses to define the name of the directive provider
- @Component({ selector: 'noosfero-custom-block', template: "My Custom Block " })
- class CustomBlock {
- @Input() block: any;
- @Input() owner: any;
- }
-
- @Component({ selector: 'test-container-component', template: htmlTemplate, directives: [Block, CustomBlock] })
- class CustomBlockType {
- block = { type: 'CustomBlock' };
- owner = { name: 'profile-name' };
- constructor() {
- }
- }
- tcb
- .createAsync(CustomBlockType).then(fixture => {
- let myComponent: CustomBlockType = fixture.componentInstance;
- expect(myComponent.block.type).toEqual("CustomBlock");
- expect(fixture.debugElement.componentViewChildren[0].text()).toEqual("My Custom Block");
- done();
- });
- });
-
-
- it("renders the default block when hasn't defined a block type", done => {
- @Component({ selector: 'test-container-component', template: htmlTemplate, directives: [Block] })
- class CustomBlockType {
- block: any = { type: null };
- owner: any = { name: 'profile-name' };
- constructor() {
- }
- }
- tcb
- .createAsync(CustomBlockType).then(fixture => {
- let myComponent: CustomBlockType = fixture.componentInstance;
- expect(myComponent.block.type).toBeNull();
- expect(!!fixture.debugElement.nativeElement.querySelector("noosfero-default-block")).toBeTruthy();
- done();
- });
- });
-
- });
-});
\ No newline at end of file
diff --git a/src/app/components/noosfero-blocks/block.component.ts b/src/app/components/noosfero-blocks/block.component.ts
deleted file mode 100644
index e9d2207..0000000
--- a/src/app/components/noosfero-blocks/block.component.ts
+++ /dev/null
@@ -1,20 +0,0 @@
-import { Input, Inject, Component } from 'ng-forward';
-
-@Component({
- selector: 'noosfero-block',
- template: '
'
-})
-@Inject("$element", "$scope", "$injector", "$compile")
-export class Block {
-
- @Input() block: any;
- @Input() owner: any;
-
- ngOnInit() {
- let blockName = (this.block && this.block.type) ? this.block.type.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase() : "default-block";
- this.$element.replaceWith(this.$compile(' ')(this.$scope));
- }
-
- constructor(private $element: any, private $scope: ng.IScope, private $injector: ng.auto.IInjectorService, private $compile: ng.ICompileService) {
- }
-}
diff --git a/src/app/components/noosfero-blocks/block.scss b/src/app/components/noosfero-blocks/block.scss
deleted file mode 100644
index f6df6ba..0000000
--- a/src/app/components/noosfero-blocks/block.scss
+++ /dev/null
@@ -1,10 +0,0 @@
-.block {
- .panel-title {
- font-size: 15px;
- font-weight: bold;
- }
- .panel-heading {
- background-color: transparent;
- border: 0;
- }
-}
diff --git a/src/app/components/noosfero-blocks/index.ts b/src/app/components/noosfero-blocks/index.ts
deleted file mode 100644
index 3f70547..0000000
--- a/src/app/components/noosfero-blocks/index.ts
+++ /dev/null
@@ -1,2 +0,0 @@
-/* Module Index Entry - generated using the script npm run generate-index */
-export * from "./block.component";
diff --git a/src/app/components/noosfero-blocks/link-list/index.ts b/src/app/components/noosfero-blocks/link-list/index.ts
deleted file mode 100644
index 765aba8..0000000
--- a/src/app/components/noosfero-blocks/link-list/index.ts
+++ /dev/null
@@ -1,2 +0,0 @@
-/* Module Index Entry - generated using the script npm run generate-index */
-export * from "./link-list.component";
diff --git a/src/app/components/noosfero-blocks/link-list/link-list.component.spec.ts b/src/app/components/noosfero-blocks/link-list/link-list.component.spec.ts
deleted file mode 100644
index 1964548..0000000
--- a/src/app/components/noosfero-blocks/link-list/link-list.component.spec.ts
+++ /dev/null
@@ -1,65 +0,0 @@
-import {TestComponentBuilder} from 'ng-forward/cjs/testing/test-component-builder';
-import {Pipe, Input, provide, Component} from 'ng-forward';
-import {provideFilters} from '../../../../spec/helpers';
-
-import {LinkListBlock} from './link-list.component';
-
-const tcb = new TestComponentBuilder();
-
-const htmlTemplate: string = ' ';
-
-
-describe("Components", () => {
-
- describe("Link List Block Component", () => {
-
- beforeEach(angular.mock.module("templates"));
-
- it("receives the block and the owner as inputs", done => {
-
- // Creating a container component (BlockContainerComponent) to include
- // the component under test (Block)
- @Component({ selector: 'test-container-component', template: htmlTemplate, directives: [LinkListBlock] })
- class BlockContainerComponent {
- block = { type: 'Block' };
- owner = { name: 'profile-name' };
- constructor() {
- }
- }
-
- // uses the TestComponentBuilder instance to initialize the component
- // .overrideView(LinkListBlock, { template: 'asdasdasd', pipes: [NoosferoTemplate] })
- tcb.createAsync(BlockContainerComponent).then(fixture => {
- // and here we can inspect and run the test assertions
- let myComponent: LinkListBlock = fixture.componentInstance;
-
- // assure the block object inside the Block matches
- // the provided through the parent component
- expect(myComponent.block.type).toEqual("Block");
- expect(myComponent.owner.name).toEqual("profile-name");
- done();
- });
- });
-
-
- it("display links stored in block settings", done => {
-
- @Component({
- selector: 'test-container-component',
- template: htmlTemplate,
- directives: [LinkListBlock],
- providers: provideFilters("noosferoTemplateFilter")
- })
- class CustomBlockType {
- block: any = { settings: { links: [{ name: 'link1', address: 'address1' }, { name: 'link2', address: 'address2' }] } };
- owner: any = { name: 'profile-name' };
- }
- tcb.createAsync(CustomBlockType).then(fixture => {
- expect(fixture.debugElement.queryAll(".link-list-block a").length).toEqual(2);
- done();
- });
- });
-
- });
-
-});
\ No newline at end of file
diff --git a/src/app/components/noosfero-blocks/link-list/link-list.component.ts b/src/app/components/noosfero-blocks/link-list/link-list.component.ts
deleted file mode 100644
index 0f89091..0000000
--- a/src/app/components/noosfero-blocks/link-list/link-list.component.ts
+++ /dev/null
@@ -1,20 +0,0 @@
-import {Component, Input} from "ng-forward";
-
-@Component({
- selector: "noosfero-link-list-block",
- templateUrl: "app/components/noosfero-blocks/link-list/link-list.html"
-})
-export class LinkListBlock {
-
- @Input() block: any;
- @Input() owner: any;
-
- links: any;
-
- ngOnInit() {
- if (this.block && this.block.settings) {
- this.links = this.block.settings.links;
- }
- }
-
-}
diff --git a/src/app/components/noosfero-blocks/link-list/link-list.html b/src/app/components/noosfero-blocks/link-list/link-list.html
deleted file mode 100644
index 17db1db..0000000
--- a/src/app/components/noosfero-blocks/link-list/link-list.html
+++ /dev/null
@@ -1,7 +0,0 @@
-
diff --git a/src/app/components/noosfero-blocks/link-list/link-list.scss b/src/app/components/noosfero-blocks/link-list/link-list.scss
deleted file mode 100644
index bd60824..0000000
--- a/src/app/components/noosfero-blocks/link-list/link-list.scss
+++ /dev/null
@@ -1,34 +0,0 @@
-.icon-event {
- @extend .fa-calendar;
-}
-.icon-photos {
- @extend .fa-photo;
-}
-.icon-edit {
- @extend .fa-edit;
-}
-.icon-ok {
- @extend .fa-check;
-}
-.icon-send {
- @extend .fa-send-o;
-}
-.icon-menu-people {
- @extend .fa-user;
-}
-.icon-forum {
- @extend .fa-users;
-}
-.icon-new {
- @extend .fa-file-o;
-}
-.icon-save {
- @extend .fa-save;
-}
-
-.link-list-block {
- a i {
- line-height: 25px;
- color: #949494;
- }
-}
diff --git a/src/app/components/noosfero-blocks/main-block/index.ts b/src/app/components/noosfero-blocks/main-block/index.ts
deleted file mode 100644
index 4206e70..0000000
--- a/src/app/components/noosfero-blocks/main-block/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-/* Module Index Entry - generated using the script npm run generate-index */
diff --git a/src/app/components/noosfero-blocks/main-block/main-block.component.spec.ts b/src/app/components/noosfero-blocks/main-block/main-block.component.spec.ts
deleted file mode 100644
index e74671a..0000000
--- a/src/app/components/noosfero-blocks/main-block/main-block.component.spec.ts
+++ /dev/null
@@ -1,40 +0,0 @@
-import {TestComponentBuilder} from 'ng-forward/cjs/testing/test-component-builder';
-import {Input, provide, Component, StateConfig} from 'ng-forward';
-
-import {MainBlock} from './main-block.component';
-import {NoosferoApp} from '../../../index.module';
-
-const tcb = new TestComponentBuilder();
-
-const htmlTemplate: string = ' ';
-
-describe("Components", () => {
- describe("Main Block Component", () => {
-
- // the karma preprocessor html2js transform the templates html into js files which put
- // the templates to the templateCache into the module templates
- // we need to load the module templates here as the template for the
- // component Block will be load on our tests
- beforeEach(angular.mock.module("templates"));
-
- it("check if the main block has a tag with ui-view attribute", done => {
-
- // Creating a container component (BlockContainerComponent) to include
- // the component under test (Block)
- @Component({ selector: 'test-container-component', template: htmlTemplate, directives: [MainBlock] })
- class BlockContainerComponent {
- }
-
- // uses the TestComponentBuilder instance to initialize the component
- tcb.createAsync(BlockContainerComponent).then(fixture => {
- // and here we can inspect and run the test assertions
- // let myComponent: MainBlock = fixture.componentInstance;
-
- // assure the block object inside the Block matches
- // the provided through the parent component
- expect(fixture.debugElement.queryAll('[ui-view="mainBlockContent"]').length).toEqual(1);
- done();
- });
- });
- });
-});
\ No newline at end of file
diff --git a/src/app/components/noosfero-blocks/main-block/main-block.component.ts b/src/app/components/noosfero-blocks/main-block/main-block.component.ts
deleted file mode 100644
index 3d334a2..0000000
--- a/src/app/components/noosfero-blocks/main-block/main-block.component.ts
+++ /dev/null
@@ -1,10 +0,0 @@
-import {Component, Input} from 'ng-forward';
-import {Block} from '../block.component';
-
-@Component({
- selector: 'noosfero-main-block',
- templateUrl: 'app/components/noosfero-blocks/main-block/main-block.html'
-})
-export class MainBlock {
-
-}
diff --git a/src/app/components/noosfero-blocks/main-block/main-block.html b/src/app/components/noosfero-blocks/main-block/main-block.html
deleted file mode 100644
index 129d0a2..0000000
--- a/src/app/components/noosfero-blocks/main-block/main-block.html
+++ /dev/null
@@ -1 +0,0 @@
-
diff --git a/src/app/components/noosfero-blocks/members-block/index.ts b/src/app/components/noosfero-blocks/members-block/index.ts
deleted file mode 100644
index 4206e70..0000000
--- a/src/app/components/noosfero-blocks/members-block/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-/* Module Index Entry - generated using the script npm run generate-index */
diff --git a/src/app/components/noosfero-blocks/members-block/members-block.component.spec.ts b/src/app/components/noosfero-blocks/members-block/members-block.component.spec.ts
deleted file mode 100644
index a621154..0000000
--- a/src/app/components/noosfero-blocks/members-block/members-block.component.spec.ts
+++ /dev/null
@@ -1,53 +0,0 @@
-import {TestComponentBuilder} from 'ng-forward/cjs/testing/test-component-builder';
-import {Provider, Input, provide, Component} from 'ng-forward';
-
-import {MembersBlock} from './members-block.component';
-
-const htmlTemplate: string = ' ';
-
-const tcb = new TestComponentBuilder();
-
-describe("Components", () => {
- describe("Members Block Component", () => {
-
- beforeEach(angular.mock.module("templates"));
-
- let state = jasmine.createSpyObj("state", ["go"]);
- let providers = [
- new Provider('truncateFilter', { useValue: () => { } }),
- new Provider('stripTagsFilter', { useValue: () => { } }),
- new Provider('$state', { useValue: state }),
- new Provider('ProfileService', {
- useValue: {
- getProfileMembers: (profileId: number, filters: any): any => {
- return Promise.resolve({ data: { people: [{ identifier: "person1" }] } });
- }
- }
- }),
- ];
- @Component({ selector: 'test-container-component', template: htmlTemplate, directives: [MembersBlock], providers: providers })
- class BlockContainerComponent {
- block = { type: 'Block', settings: {} };
- owner = { name: 'profile-name' };
- constructor() {
- }
- }
-
- it("get members of the block owner", done => {
- tcb.createAsync(BlockContainerComponent).then(fixture => {
- let block: MembersBlock = fixture.debugElement.componentViewChildren[0].componentInstance;
- expect(block.members).toEqual([{ identifier: "person1" }]);
- done();
- });
- });
-
- it("render the profile image for each member", done => {
- tcb.createAsync(BlockContainerComponent).then(fixture => {
- fixture.debugElement.getLocal("$rootScope").$apply();
- expect(fixture.debugElement.queryAll("noosfero-profile-image").length).toEqual(1);
- done();
- });
- });
-
- });
-});
\ No newline at end of file
diff --git a/src/app/components/noosfero-blocks/members-block/members-block.component.ts b/src/app/components/noosfero-blocks/members-block/members-block.component.ts
deleted file mode 100644
index 108d8ca..0000000
--- a/src/app/components/noosfero-blocks/members-block/members-block.component.ts
+++ /dev/null
@@ -1,25 +0,0 @@
-import {Input, Inject, Component} from "ng-forward";
-import {ProfileService} from "../../../../lib/ng-noosfero-api/http/profile.service";
-
-@Component({
- selector: "noosfero-members-block",
- templateUrl: 'app/components/noosfero-blocks/members-block/members-block.html',
-})
-@Inject(ProfileService)
-export class MembersBlock {
-
- @Input() block: noosfero.Block;
- @Input() owner: noosfero.Profile;
-
- members: any = [];
-
- constructor(private profileService: ProfileService) {
-
- }
-
- ngOnInit() {
- this.profileService.getProfileMembers(this.owner.id, { per_page: 6 }).then((response: any) => {
- this.members = response.data.people;
- });
- }
-}
diff --git a/src/app/components/noosfero-blocks/members-block/members-block.html b/src/app/components/noosfero-blocks/members-block/members-block.html
deleted file mode 100644
index 913c149..0000000
--- a/src/app/components/noosfero-blocks/members-block/members-block.html
+++ /dev/null
@@ -1,5 +0,0 @@
-
diff --git a/src/app/components/noosfero-blocks/members-block/members-block.scss b/src/app/components/noosfero-blocks/members-block/members-block.scss
deleted file mode 100644
index c5776e0..0000000
--- a/src/app/components/noosfero-blocks/members-block/members-block.scss
+++ /dev/null
@@ -1,17 +0,0 @@
-.members-block {
- .member {
- img, i.profile-image {
- width: 60px;
- }
- img {
- display: inline-block;
- vertical-align: top;
- }
- i.profile-image {
- text-align: center;
- background-color: #889DB1;
- color: #F1F1F1;
- font-size: 4.5em;
- }
- }
-}
diff --git a/src/app/components/noosfero-blocks/profile-image-block/profile-image-block.component.spec.ts b/src/app/components/noosfero-blocks/profile-image-block/profile-image-block.component.spec.ts
deleted file mode 100644
index 6832be7..0000000
--- a/src/app/components/noosfero-blocks/profile-image-block/profile-image-block.component.spec.ts
+++ /dev/null
@@ -1,46 +0,0 @@
-import {TestComponentBuilder, ComponentFixture} from 'ng-forward/cjs/testing/test-component-builder';
-import {Pipe, Input, provide, Component} from 'ng-forward';
-
-import {ProfileImageBlock} from './profile-image-block.component';
-
-import * as helpers from "./../../../../spec/helpers";
-
-const tcb = new TestComponentBuilder();
-
-const htmlTemplate: string = ' ';
-
-describe("Components", () => {
-
- describe("Profile Image Block Component", () => {
-
- beforeEach(angular.mock.module("templates"));
-
- @Component({
- selector: 'test-container-component',
- template: htmlTemplate,
- directives: [ProfileImageBlock],
- providers: helpers.provideFilters("translateFilter")
- })
- class BlockContainerComponent {
- block = { type: 'Block' };
- owner = { name: 'profile-name' };
- constructor() {
- }
- }
-
- it("show image if present", () => {
- helpers.tcb.createAsync(BlockContainerComponent).then(fixture => {
- let elProfile = fixture.debugElement.componentViewChildren[0];
- expect(elProfile.query('div.profile-image-block').length).toEqual(1);
- });
- });
-
- it("has link to the profile", () => {
- helpers.tcb.createAsync(BlockContainerComponent).then(fixture => {
- let elProfile = fixture.debugElement.componentViewChildren[0];
- expect(elProfile.query('a.settings-link').length).toEqual(1);
- });
- });
-
- });
-});
diff --git a/src/app/components/noosfero-blocks/profile-image-block/profile-image-block.component.ts b/src/app/components/noosfero-blocks/profile-image-block/profile-image-block.component.ts
deleted file mode 100644
index ab4f387..0000000
--- a/src/app/components/noosfero-blocks/profile-image-block/profile-image-block.component.ts
+++ /dev/null
@@ -1,14 +0,0 @@
-import {Inject, Input, Component} from "ng-forward";
-import {ProfileImage} from "./../../../components/noosfero/profile-image/profile-image.component";
-
-@Component({
- selector: "noosfero-profile-image-block",
- templateUrl: 'app/components/noosfero-blocks/profile-image-block/profile-image-block.html',
- directives: [ProfileImage]
-})
-export class ProfileImageBlock {
-
- @Input() block: noosfero.Block;
- @Input() owner: noosfero.Profile;
-
-}
diff --git a/src/app/components/noosfero-blocks/profile-image-block/profile-image-block.html b/src/app/components/noosfero-blocks/profile-image-block/profile-image-block.html
deleted file mode 100644
index f9159e3..0000000
--- a/src/app/components/noosfero-blocks/profile-image-block/profile-image-block.html
+++ /dev/null
@@ -1,6 +0,0 @@
-
diff --git a/src/app/components/noosfero-blocks/profile-image-block/profile-image-block.scss b/src/app/components/noosfero-blocks/profile-image-block/profile-image-block.scss
deleted file mode 100644
index a609250..0000000
--- a/src/app/components/noosfero-blocks/profile-image-block/profile-image-block.scss
+++ /dev/null
@@ -1,5 +0,0 @@
-.profile-image-block {
- .settings-link {
- display: block;
- }
-}
diff --git a/src/app/components/noosfero-blocks/raw-html/raw-html.component.spec.ts b/src/app/components/noosfero-blocks/raw-html/raw-html.component.spec.ts
deleted file mode 100644
index b5c1d4b..0000000
--- a/src/app/components/noosfero-blocks/raw-html/raw-html.component.spec.ts
+++ /dev/null
@@ -1,36 +0,0 @@
-import {TestComponentBuilder} from 'ng-forward/cjs/testing/test-component-builder';
-import {Component} from 'ng-forward';
-
-import {RawHTMLBlock} from './raw-html.component';
-
-const tcb = new TestComponentBuilder();
-
-const htmlTemplate: string = ' ';
-
-describe("Components", () => {
-
- describe("Raw Html Block Component", () => {
-
- beforeEach(angular.mock.module("templates"));
- beforeEach(angular.mock.module("ngSanitize"));
-
- it("display html stored in block settings", done => {
-
- @Component({
- selector: 'test-container-component',
- template: htmlTemplate,
- directives: [RawHTMLBlock],
- })
- class CustomBlockType {
- block: any = { settings: { html: 'block content ' } };
- owner: any = { name: 'profile-name' };
- }
- tcb.createAsync(CustomBlockType).then(fixture => {
- expect(fixture.debugElement.query(".raw-html-block em").text().trim()).toEqual('block content');
- done();
- });
- });
-
- });
-
-});
diff --git a/src/app/components/noosfero-blocks/raw-html/raw-html.component.ts b/src/app/components/noosfero-blocks/raw-html/raw-html.component.ts
deleted file mode 100644
index 33a241c..0000000
--- a/src/app/components/noosfero-blocks/raw-html/raw-html.component.ts
+++ /dev/null
@@ -1,18 +0,0 @@
-import {Component, Input} from "ng-forward";
-
-@Component({
- selector: "noosfero-raw-htmlblock",
- templateUrl: 'app/components/noosfero-blocks/raw-html/raw-html.html'
-})
-
-export class RawHTMLBlock {
-
- @Input() block: any;
- @Input() owner: any;
-
- html: string;
-
- ngOnInit() {
- this.html = this.block.settings.html;
- }
-}
diff --git a/src/app/components/noosfero-blocks/raw-html/raw-html.html b/src/app/components/noosfero-blocks/raw-html/raw-html.html
deleted file mode 100644
index af6cf33..0000000
--- a/src/app/components/noosfero-blocks/raw-html/raw-html.html
+++ /dev/null
@@ -1,2 +0,0 @@
-
-
diff --git a/src/app/components/noosfero-blocks/recent-documents/index.ts b/src/app/components/noosfero-blocks/recent-documents/index.ts
deleted file mode 100644
index 4206e70..0000000
--- a/src/app/components/noosfero-blocks/recent-documents/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-/* Module Index Entry - generated using the script npm run generate-index */
diff --git a/src/app/components/noosfero-blocks/recent-documents/recent-documents.component.spec.ts b/src/app/components/noosfero-blocks/recent-documents/recent-documents.component.spec.ts
deleted file mode 100644
index 54a9674..0000000
--- a/src/app/components/noosfero-blocks/recent-documents/recent-documents.component.spec.ts
+++ /dev/null
@@ -1,80 +0,0 @@
-import {TestComponentBuilder} from 'ng-forward/cjs/testing/test-component-builder';
-import {Provider, Input, provide, Component} from 'ng-forward';
-import {provideFilters} from '../../../../spec/helpers';
-import {RecentDocumentsBlock} from './recent-documents.component';
-
-const htmlTemplate: string = ' ';
-
-const tcb = new TestComponentBuilder();
-
-describe("Components", () => {
- describe("Recent Documents Block Component", () => {
-
- let settingsObj = {};
- let mockedArticleService = {
- getByProfile: (profile: noosfero.Profile, filters: any): any => {
- return Promise.resolve({ data: [{ name: "article1" }], headers: (name: string) => { return name; } });
- }
- };
- let profile = { name: 'profile-name' };
- beforeEach(angular.mock.module("templates"));
-
- let state = jasmine.createSpyObj("state", ["go"]);
-
-
- function getProviders() {
- return [
- new Provider('$state', { useValue: state }),
- new Provider('ArticleService', {
- useValue: mockedArticleService
- }),
- ].concat(provideFilters("truncateFilter", "stripTagsFilter"));
- }
- let componentClass: any = null;
-
- function getComponent() {
- @Component({ selector: 'test-container-component', template: htmlTemplate, directives: [RecentDocumentsBlock], providers: getProviders() })
- class BlockContainerComponent {
- block = { type: 'Block', settings: settingsObj };
- owner = profile;
- constructor() {
- }
- }
- return BlockContainerComponent;
- }
-
-
- it("get recent documents from the article service", done => {
- tcb.createAsync(getComponent()).then(fixture => {
- let recentDocumentsBlock: RecentDocumentsBlock = fixture.debugElement.componentViewChildren[0].componentInstance;
- expect(recentDocumentsBlock.documents).toEqual([{ name: "article1" }]);
- done();
- });
- });
-
- it("go to article page when open a document", done => {
- tcb.createAsync(getComponent()).then(fixture => {
- let recentDocumentsBlock: RecentDocumentsBlock = fixture.debugElement.componentViewChildren[0].componentInstance;
- recentDocumentsBlock.openDocument({ path: "path", profile: { identifier: "identifier" } });
- expect(state.go).toHaveBeenCalledWith("main.profile.page", { page: "path", profile: "identifier" });
- done();
- });
- });
-
- it("it uses default limit 5 if not defined on block", done => {
- settingsObj = null;
- mockedArticleService = jasmine.createSpyObj("mockedArticleService", ["getByProfile"]);
- (mockedArticleService).mocked = true;
- let thenMocked = jasmine.createSpy("then");
- mockedArticleService.getByProfile = jasmine.createSpy("getByProfile").and.returnValue({then: thenMocked});
- let getByProfileFunct = mockedArticleService.getByProfile;
- tcb.createAsync(getComponent()).then(fixture => {
- let recentDocumentsBlock: RecentDocumentsBlock = fixture.debugElement.componentViewChildren[0].componentInstance;
- recentDocumentsBlock.openDocument({ path: "path", profile: { identifier: "identifier" } });
- expect(getByProfileFunct).toHaveBeenCalledWith(profile, { content_type: 'TinyMceArticle', per_page: 5 });
- done();
- });
- });
-
- });
-});
\ No newline at end of file
diff --git a/src/app/components/noosfero-blocks/recent-documents/recent-documents.component.ts b/src/app/components/noosfero-blocks/recent-documents/recent-documents.component.ts
deleted file mode 100644
index 9997e57..0000000
--- a/src/app/components/noosfero-blocks/recent-documents/recent-documents.component.ts
+++ /dev/null
@@ -1,41 +0,0 @@
-import {Component, Inject, Input} from "ng-forward";
-import {ArticleService} from "../../../../lib/ng-noosfero-api/http/article.service";
-
-@Component({
- selector: "noosfero-recent-documents-block",
- templateUrl: 'app/components/noosfero-blocks/recent-documents/recent-documents.html'
-})
-@Inject(ArticleService, "$state")
-export class RecentDocumentsBlock {
-
- @Input() block: any;
- @Input() owner: any;
-
- profile: any;
- documents: any;
-
- documentsLoaded: boolean = false;
-
- constructor(private articleService: ArticleService, private $state: any) {
- }
-
- ngOnInit() {
- this.profile = this.owner;
- this.documents = [];
-
- let limit = ((this.block && this.block.settings) ? this.block.settings.limit : null) || 5;
- // FIXME get all text articles
- // FIXME make the getByProfile a generic method where we tell the type passing a class TinyMceArticle
- // and the promise should be of type TinyMceArticle[], per example
- this.articleService.getByProfile(this.profile, { content_type: 'TinyMceArticle', per_page: limit })
- .then((result: noosfero.RestResult) => {
- this.documents = result.data;
- this.documentsLoaded = true;
- });
- }
-
- openDocument(article: any) {
- this.$state.go("main.profile.page", { page: article.path, profile: article.profile.identifier });
- }
-
-}
diff --git a/src/app/components/noosfero-blocks/recent-documents/recent-documents.html b/src/app/components/noosfero-blocks/recent-documents/recent-documents.html
deleted file mode 100644
index 1421cfe..0000000
--- a/src/app/components/noosfero-blocks/recent-documents/recent-documents.html
+++ /dev/null
@@ -1,18 +0,0 @@
-
diff --git a/src/app/components/noosfero-blocks/recent-documents/recent-documents.scss b/src/app/components/noosfero-blocks/recent-documents/recent-documents.scss
deleted file mode 100644
index 74cf5e9..0000000
--- a/src/app/components/noosfero-blocks/recent-documents/recent-documents.scss
+++ /dev/null
@@ -1,65 +0,0 @@
-.block.recentdocumentsblock {
- .deckgrid[deckgrid]::before {
- font-size: 0; /* See https://github.com/akoenig/angular-deckgrid/issues/14#issuecomment-35728861 */
- visibility: hidden;
- }
- .author {
- img {
- width: 30px;
- height: 30px;
- }
- }
- .header {
- .subheader {
- color: #C1C1C1;
- font-size: 10px;
- }
- }
- .post-lead {
- color: #8E8E8E;
- font-size: 14px;
- }
- .article-image {
- margin: 10px 0;
- }
-}
-
-.col-md-2-5 {
- .deckgrid[deckgrid]::before {
- content: '1 .deck-column';
- }
-}
-
-.col-md-7 {
- .block.recentdocumentsblock {
- background-color: transparent;
- border: 0;
-
- .deckgrid[deckgrid]::before {
- content: '3 .deck-column';
- }
-
- .panel-heading {
- display: none;
- }
- .panel-body {
- padding: 0;
- }
-
- .deckgrid {
- .column {
- float: left;
- }
-
- .deck-column {
- @extend .col-md-4;
- padding: 0;
-
- .a-card {
- padding: 10px;
- margin: 3px;
- }
- }
- }
- }
-}
diff --git a/src/app/components/noosfero-boxes/box.html b/src/app/components/noosfero-boxes/box.html
deleted file mode 100644
index 4550503..0000000
--- a/src/app/components/noosfero-boxes/box.html
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
{{block.title}}
-
-
-
-
-
-
diff --git a/src/app/components/noosfero-boxes/boxes.component.spec.ts b/src/app/components/noosfero-boxes/boxes.component.spec.ts
deleted file mode 100644
index 8ad4510..0000000
--- a/src/app/components/noosfero-boxes/boxes.component.spec.ts
+++ /dev/null
@@ -1,65 +0,0 @@
-import {Component} from 'ng-forward';
-
-import {Boxes} from './boxes.component';
-
-import {
- createComponentFromClass,
- quickCreateComponent,
- provideEmptyObjects,
- createProviderToValue,
- getAngularServiceFactory,
- provideFilters
-} from "../../../spec/helpers";
-
-// this htmlTemplate will be re-used between the container components in this spec file
-const htmlTemplate: string = '';
-
-
-describe("Boxes Component", () => {
-
- beforeEach(() => {
- angular.mock.module("templates");
- });
-
- @Component({
- selector: 'test-container-component',
- template: htmlTemplate,
- directives: [Boxes],
- providers: []
- })
- class BoxesContainerComponent {
- boxes: noosfero.Box[] = [
- { id: 1, position: 1 },
- { id: 2, position: 2 }
- ];
-
- owner: noosfero.Profile = {
- id: 1,
- identifier: 'profile-name',
- type: 'Person'
- };
- }
-
- it("renders boxes into a container", (done: Function) => {
- createComponentFromClass(BoxesContainerComponent).then((fixture) => {
- let boxesHtml = fixture.debugElement;
- expect(boxesHtml.query('div.col-md-7').length).toEqual(1);
- expect(boxesHtml.query('div.col-md-2-5').length).toEqual(1);
-
- done();
- });
- });
-
- it("check the boxes order", (done: Function) => {
- createComponentFromClass(BoxesContainerComponent).then((fixture) => {
-
- let boxesComponent: Boxes = fixture.debugElement.componentViewChildren[0].componentInstance;
- let boxesContainer: BoxesContainerComponent = fixture.componentInstance;
-
- expect(boxesComponent.boxesOrder(boxesContainer.boxes[0])).toEqual(1);
- expect(boxesComponent.boxesOrder(boxesContainer.boxes[1])).toEqual(0);
-
- done();
- });
- });
-});
diff --git a/src/app/components/noosfero-boxes/boxes.component.ts b/src/app/components/noosfero-boxes/boxes.component.ts
deleted file mode 100644
index ff52b54..0000000
--- a/src/app/components/noosfero-boxes/boxes.component.ts
+++ /dev/null
@@ -1,16 +0,0 @@
-import {Input, Inject, Component} from 'ng-forward';
-
-@Component({
- selector: "noosfero-boxes",
- templateUrl: "app/components/noosfero-boxes/boxes.html"
-})
-export class Boxes {
-
- @Input() boxes: noosfero.Box[];
- @Input() owner: noosfero.Profile;
-
- boxesOrder(box: noosfero.Box) {
- if (box.position === 2) return 0;
- return box.position;
- }
-}
diff --git a/src/app/components/noosfero-boxes/boxes.html b/src/app/components/noosfero-boxes/boxes.html
deleted file mode 100644
index 7dd1978..0000000
--- a/src/app/components/noosfero-boxes/boxes.html
+++ /dev/null
@@ -1 +0,0 @@
-
diff --git a/src/app/components/noosfero-boxes/boxes.scss b/src/app/components/noosfero-boxes/boxes.scss
deleted file mode 100644
index 9e6d526..0000000
--- a/src/app/components/noosfero-boxes/boxes.scss
+++ /dev/null
@@ -1,6 +0,0 @@
-.col-md-2-5 {
- @extend .col-md-3;
- @media (min-width: 920px) {
- width: 20.83%;
- }
-}
diff --git a/src/app/components/noosfero-boxes/index.ts b/src/app/components/noosfero-boxes/index.ts
deleted file mode 100644
index 6369864..0000000
--- a/src/app/components/noosfero-boxes/index.ts
+++ /dev/null
@@ -1,2 +0,0 @@
-/* Module Index Entry - generated using the script npm run generate-index */
-export * from "./boxes.component";
diff --git a/src/app/components/noosfero/date-format/date-format.filter.spec.ts b/src/app/components/noosfero/date-format/date-format.filter.spec.ts
deleted file mode 100644
index 88d699c..0000000
--- a/src/app/components/noosfero/date-format/date-format.filter.spec.ts
+++ /dev/null
@@ -1,20 +0,0 @@
-import {quickCreateComponent} from "../../../../spec/helpers";
-import {DateFormat} from './date-format.filter';
-
-describe("Filters", () => {
- describe("Date Format Filter", () => {
-
- beforeEach(angular.mock.module("templates"));
- beforeEach(angular.mock.module("angularMoment"));
-
- it("convert date from the format returned by noosfero api to an ISO format", done => {
- let date = "2016/03/10 10:46:47";
- let htmlTemplate = `{{ '${date}' | dateFormat }}`;
- quickCreateComponent({ providers: [DateFormat], template: htmlTemplate }).then(fixture => {
- expect(fixture.debugElement.text()).toEqual('2016-03-10T13:46:47.000Z');
- done();
- });
- });
-
- });
-});
diff --git a/src/app/components/noosfero/date-format/date-format.filter.ts b/src/app/components/noosfero/date-format/date-format.filter.ts
deleted file mode 100644
index 00ffa4d..0000000
--- a/src/app/components/noosfero/date-format/date-format.filter.ts
+++ /dev/null
@@ -1,13 +0,0 @@
-import {Pipe, Inject} from "ng-forward";
-
-@Pipe("dateFormat")
-@Inject("amParseFilter")
-export class DateFormat {
-
- constructor(private amParseFilter: any) { }
-
- transform(date: string, options: any) {
- return this.amParseFilter(date, "YYYY/MM/DD HH:mm:ss").toISOString();
- }
-
-}
diff --git a/src/app/components/noosfero/index.ts b/src/app/components/noosfero/index.ts
deleted file mode 100644
index 4206e70..0000000
--- a/src/app/components/noosfero/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-/* Module Index Entry - generated using the script npm run generate-index */
diff --git a/src/app/components/noosfero/noosfero-template.filter.spec.ts b/src/app/components/noosfero/noosfero-template.filter.spec.ts
deleted file mode 100644
index 0e7b613..0000000
--- a/src/app/components/noosfero/noosfero-template.filter.spec.ts
+++ /dev/null
@@ -1,19 +0,0 @@
-import {quickCreateComponent} from "../../../spec/helpers";
-import {NoosferoTemplate} from './noosfero-template.filter';
-
-describe("Filters", () => {
- describe("Noosfero Template Filter", () => {
-
- beforeEach(angular.mock.module("templates"));
-
- it("replace the options in text with the values passed on options", done => {
- let text = 'profile: {profile}, other: {other}';
- let htmlTemplate = `{{ '${text}' | noosferoTemplate: {profile: 'profile1', other: 'other value'} }}`;
- quickCreateComponent({ providers: [NoosferoTemplate], template: htmlTemplate }).then(fixture => {
- expect(fixture.debugElement.text()).toEqual("profile: profile1, other: other value");
- done();
- });
- });
-
- });
-});
diff --git a/src/app/components/noosfero/noosfero-template.filter.ts b/src/app/components/noosfero/noosfero-template.filter.ts
deleted file mode 100644
index a7cd0df..0000000
--- a/src/app/components/noosfero/noosfero-template.filter.ts
+++ /dev/null
@@ -1,13 +0,0 @@
-import {Pipe} from "ng-forward";
-
-@Pipe("noosferoTemplate")
-export class NoosferoTemplate {
-
- transform(text: string, options: any) {
- for (let option in options) {
- text = text.replace('{' + option + '}', options[option]);
- }
- return text;
- }
-
-}
diff --git a/src/app/components/noosfero/profile-image/index.ts b/src/app/components/noosfero/profile-image/index.ts
deleted file mode 100644
index f7507cc..0000000
--- a/src/app/components/noosfero/profile-image/index.ts
+++ /dev/null
@@ -1,5 +0,0 @@
-/**
- * Module for the image component in the Noosfero Angular Theme
- * @namespace components.noosfero.profile-image
- */
-/* Module Index Entry - generated using the script npm run generate-index */
diff --git a/src/app/components/noosfero/profile-image/profile-image.component.spec.ts b/src/app/components/noosfero/profile-image/profile-image.component.spec.ts
deleted file mode 100644
index 84a6045..0000000
--- a/src/app/components/noosfero/profile-image/profile-image.component.spec.ts
+++ /dev/null
@@ -1,51 +0,0 @@
-/**
- * @ngdoc overview
- * @name components.noosfero.profile-image.ProfileImageSpec
- * @description
- * This file contains the tests for the {@link components.noosfero.profile-image.ProfileImage} component.
- */
-
-import {TestComponentBuilder, ComponentFixture} from 'ng-forward/cjs/testing/test-component-builder';
-import {Pipe, Input, provide, Component} from 'ng-forward';
-
-import * as helpers from "./../../../../spec/helpers";
-
-import {ProfileImage} from "./profile-image.component";
-
-const tcb = new TestComponentBuilder();
-
-describe("Components", () => {
-
- describe("Profile Image Component", () => {
-
- beforeEach(angular.mock.module("templates"));
-
- it("show community users image if profile is not Person", done => {
- helpers.tcb.createAsync(ProfileImage).then(fixture => {
- let profileImageComponent: ProfileImage = fixture.componentInstance;
- let profile = { id: 1, identifier: "myprofile", type: "Community" };
- profileImageComponent.profile = profile;
- profileImageComponent.ngOnInit();
-
- // Check the attribute
- expect(profileImageComponent.defaultIcon).toBe("fa-users", "The default icon should be community users");
- // var elProfile = fixture.debugElement.componentViewChildren[0];
- // expect(elProfile.query('div.profile-image-block').length).toEqual(1);
- done();
- });
- });
-
- it("show Person image if profile is Person", done => {
- tcb.createAsync(ProfileImage).then(fixture => {
- let profileImageComponent: ProfileImage = fixture.componentInstance;
- let profile = { id: 1, identifier: "myprofile", type: "Person" };
- profileImageComponent.profile = profile;
- profileImageComponent.ngOnInit();
- // Check the attribute
- expect(profileImageComponent.defaultIcon).toEqual("fa-user", "The default icon should be person user");
- done();
- });
- });
-
- });
-});
\ No newline at end of file
diff --git a/src/app/components/noosfero/profile-image/profile-image.component.ts b/src/app/components/noosfero/profile-image/profile-image.component.ts
deleted file mode 100644
index 1a95d45..0000000
--- a/src/app/components/noosfero/profile-image/profile-image.component.ts
+++ /dev/null
@@ -1,47 +0,0 @@
-import {Inject, Input, Component} from "ng-forward";
-
-
-/**
- * @ngdoc controller
- * @name components.noosfero.profile-image.ProfileImage
- * @description The component responsible for rendering the profile image
- * @exports ProfileImage
- */
-@Component({
- selector: "noosfero-profile-image",
- templateUrl: 'app/components/noosfero/profile-image/profile-image.html',
-})
-export class ProfileImage {
-
- /**
- * @ngdoc property
- * @name profile
- * @propertyOf components.noosfero.profile-image.ProfileImage
- * @description
- * The Noosfero {@link models.Profile} holding the image.
- */
- @Input() profile: noosfero.Profile;
- /**
- * @ngdoc property
- * @name defaultIcon
- * @propertyOf components.noosfero.profile-image.ProfileImage
- * @descritpion
- * The default icon used by this profile
- */
- defaultIcon: string;
-
- /**
- * @ngdoc method
- * @name ngOnInit
- * @methodOf components.noosfero.profile-image.ProfileImage
- * @description
- * Initializes the icon names to their corresponding values depending on the profile type passed to the controller
- */
- ngOnInit() {
- this.defaultIcon = 'fa-users';
- if (this.profile && this.profile.type === 'Person') {
- this.defaultIcon = 'fa-user';
- }
- }
-}
-
diff --git a/src/app/components/noosfero/profile-image/profile-image.html b/src/app/components/noosfero/profile-image/profile-image.html
deleted file mode 100644
index b1418b6..0000000
--- a/src/app/components/noosfero/profile-image/profile-image.html
+++ /dev/null
@@ -1,4 +0,0 @@
-
-
-
-
diff --git a/src/app/components/noosfero/profile-image/profile-image.scss b/src/app/components/noosfero/profile-image/profile-image.scss
deleted file mode 100644
index f2f8fb8..0000000
--- a/src/app/components/noosfero/profile-image/profile-image.scss
+++ /dev/null
@@ -1,3 +0,0 @@
-i.profile-image {
- color: rgb(44, 62, 80);
-}
diff --git a/src/app/components/notification/notification.component.spec.ts b/src/app/components/notification/notification.component.spec.ts
deleted file mode 100644
index 5ac2742..0000000
--- a/src/app/components/notification/notification.component.spec.ts
+++ /dev/null
@@ -1,80 +0,0 @@
-import {TestComponentBuilder, ComponentFixture} from 'ng-forward/cjs/testing/test-component-builder';
-import {Pipe, Input, provide, Component} from 'ng-forward';
-
-import * as helpers from "../../../spec/helpers";
-
-import {Notification} from "./notification.component";
-
-const tcb = new TestComponentBuilder();
-
-describe("Components", () => {
-
- describe("Profile Image Component", () => {
-
- beforeEach(angular.mock.module("templates"));
-
- it("display an error message when notify an error", done => {
- let sweetAlert = jasmine.createSpyObj("sweetAlert", ["swal"]);
- sweetAlert.swal = jasmine.createSpy("swal");
-
- let component: Notification = new Notification(helpers.mocks.$log, sweetAlert, helpers.mocks.translatorService);
- component.error("message", "title");
- expect(sweetAlert.swal).toHaveBeenCalledWith(jasmine.objectContaining({
- text: "message",
- title: "title",
- type: "error"
- }));
- done();
- });
-
- it("use the default message when call notification component without a message", done => {
- let sweetAlert = jasmine.createSpyObj("sweetAlert", ["swal"]);
- sweetAlert.swal = jasmine.createSpy("swal");
-
- let component: Notification = new Notification(helpers.mocks.$log, sweetAlert, helpers.mocks.translatorService);
- component.error();
- expect(sweetAlert.swal).toHaveBeenCalledWith(jasmine.objectContaining({
- text: Notification.DEFAULT_ERROR_MESSAGE,
- type: "error"
- }));
- done();
- });
-
- it("display a success message when call notification success", done => {
- let sweetAlert = jasmine.createSpyObj("sweetAlert", ["swal"]);
- sweetAlert.swal = jasmine.createSpy("swal");
-
- let component: Notification = new Notification(helpers.mocks.$log, sweetAlert, helpers.mocks.translatorService);
- component.success("title", "message", 1000);
- expect(sweetAlert.swal).toHaveBeenCalledWith(jasmine.objectContaining({
- type: "success"
- }));
- done();
- });
-
- it("display a message relative to the http error code", done => {
- let sweetAlert = jasmine.createSpyObj("sweetAlert", ["swal"]);
- sweetAlert.swal = jasmine.createSpy("swal");
-
- let component: Notification = new Notification(helpers.mocks.$log, sweetAlert, helpers.mocks.translatorService);
- component.httpError(500, {});
- expect(sweetAlert.swal).toHaveBeenCalledWith(jasmine.objectContaining({
- text: "notification.http_error.500.message"
- }));
- done();
- });
-
- it("set the default timer in success messages", done => {
- let sweetAlert = jasmine.createSpyObj("sweetAlert", ["swal"]);
- sweetAlert.swal = jasmine.createSpy("swal");
-
- let component: Notification = new Notification(helpers.mocks.$log, sweetAlert, helpers.mocks.translatorService);
- component.success("title", "message");
- expect(sweetAlert.swal).toHaveBeenCalledWith(jasmine.objectContaining({
- type: "success",
- timer: Notification.DEFAULT_SUCCESS_TIMER
- }));
- done();
- });
- });
-});
diff --git a/src/app/components/notification/notification.component.ts b/src/app/components/notification/notification.component.ts
deleted file mode 100644
index 35c9e91..0000000
--- a/src/app/components/notification/notification.component.ts
+++ /dev/null
@@ -1,41 +0,0 @@
-import {Injectable, Inject} from "ng-forward";
-import {TranslatorService} from "../translator/translator.service";
-
-@Injectable()
-@Inject("$log", "SweetAlert", TranslatorService)
-export class Notification {
-
- constructor(
- private $log: ng.ILogService,
- private SweetAlert: any,
- private translatorService: TranslatorService
- ) { }
-
- public static DEFAULT_ERROR_TITLE = "notification.error.default.title";
- public static DEFAULT_ERROR_MESSAGE = "notification.error.default.message";
- public static DEFAULT_SUCCESS_TIMER = 1000;
-
- error(message: string = Notification.DEFAULT_ERROR_MESSAGE, title: string = Notification.DEFAULT_ERROR_TITLE) {
- this.$log.debug("Notification error:", title, message, this.translatorService.currentLanguage());
- this.SweetAlert.swal({
- title: this.translatorService.translate(title),
- text: this.translatorService.translate(message),
- type: "error"
- });
- }
-
- httpError(status: number, data: any): boolean {
- this.error(`notification.http_error.${status}.message`);
- return true; // return true to indicate that the error was already handled
- }
-
- success(title: string, text: string, timer: number = Notification.DEFAULT_SUCCESS_TIMER) {
- this.SweetAlert.swal({
- title: title,
- text: text,
- type: "success",
- timer: timer
- });
- }
-
-}
diff --git a/src/app/components/translator/translator.service.spec.ts b/src/app/components/translator/translator.service.spec.ts
deleted file mode 100644
index d1fee49..0000000
--- a/src/app/components/translator/translator.service.spec.ts
+++ /dev/null
@@ -1,116 +0,0 @@
-import {ComponentFixture} from 'ng-forward/cjs/testing/test-component-builder';
-import {provide} from 'ng-forward';
-
-import {TranslatorService} from './translator.service';
-
-import * as helpers from "../../../spec/helpers";
-
-describe("Services", () => {
-
- describe("Translator Service", () => {
-
- let $rootScope: ng.IScope;
- let $q: ng.IQService;
-
- beforeEach(inject((_$rootScope_: ng.IRootScopeService, _$q_: ng.IQService) => {
- $rootScope = _$rootScope_;
- $q = _$q_;
- }));
-
- function createComponent() {
- return new TranslatorService(
- helpers.mocks.$translate,
- helpers.mocks.tmhDynamicLocale,
- helpers.mocks.amMoment,
- helpers.mocks.angularLoad,
- $rootScope
- );
- }
-
- it("set available languages when change language", (done) => {
- let component: TranslatorService = createComponent();
- component.availableLanguages = null;
- expect(component.availableLanguages).toBeNull();
- $rootScope.$emit("$translateChangeSuccess");
- expect(component.availableLanguages).not.toBeNull();
- done();
- });
-
- it("change the language", (done) => {
- let component: TranslatorService = createComponent();
- let loadScripPromise = $q.defer();
- loadScripPromise.resolve();
- component["angularLoad"].loadScript = jasmine.createSpy("loadScript").and.returnValue(loadScripPromise.promise);
- component["tmhDynamicLocale"].set = jasmine.createSpy("set");
- component["tmhDynamicLocale"].get = jasmine.createSpy("get").and.returnValue("en");
- component["$translate"].use = jasmine.createSpy("use");
-
- component.changeLanguage('pt');
- $rootScope.$digest();
-
- expect(component["angularLoad"].loadScript).toHaveBeenCalledWith("/bower_components/moment/locale/pt.js");
- expect(component["angularLoad"].loadScript).toHaveBeenCalledWith("/bower_components/messageformat/locale/pt.js");
- expect(component["tmhDynamicLocale"].set).toHaveBeenCalledWith("pt");
- expect(component["$translate"].use).toHaveBeenCalledWith("pt");
- done();
- });
-
- it("do not load moment locale when change the language to english", (done) => {
- let component: TranslatorService = createComponent();
- component["angularLoad"].loadScript = jasmine.createSpy("loadScript").and.returnValue($q.defer().promise);
- component.changeLanguage('en');
- expect(component["angularLoad"].loadScript).not.toHaveBeenCalledWith("/bower_components/moment/locale/pt.js");
- done();
- });
-
- it("do nothing when call change language with null", (done) => {
- let component: TranslatorService = createComponent();
- component["angularLoad"].loadScript = jasmine.createSpy("loadScript");
- component["tmhDynamicLocale"].set = jasmine.createSpy("set");
- component["$translate"].use = jasmine.createSpy("use");
-
- component.changeLanguage(null);
-
- expect(component["angularLoad"].loadScript).not.toHaveBeenCalled();
- expect(component["tmhDynamicLocale"].set).not.toHaveBeenCalled();
- expect(component["$translate"].use).not.toHaveBeenCalled();
- done();
- });
-
- it("return the current language used by the translator", (done) => {
- let component: TranslatorService = createComponent();
- component["$translate"].use = jasmine.createSpy("use").and.returnValue("en");
- expect(component.currentLanguage()).toEqual("en");
- expect(component["$translate"].use).toHaveBeenCalled();
- done();
- });
-
- it("call translate service when translate a text", (done) => {
- let component: TranslatorService = createComponent();
- component["$translate"].instant = jasmine.createSpy("instant");
- component.translate("text");
- expect(component["$translate"].instant).toHaveBeenCalledWith("text");
- done();
- });
-
- it("change the language when receive an event", (done) => {
- let component: TranslatorService = createComponent();
- component.changeLanguage = jasmine.createSpy("changeLanguage");
- $rootScope.$emit("$localeChangeSuccess");
- expect(component.changeLanguage).toHaveBeenCalled();
- done();
- });
-
- it("use the translate language when receive a change language event and there is no language previously selected", (done) => {
- let component: TranslatorService = createComponent();
- component.changeLanguage = jasmine.createSpy("changeLanguage");
- component["tmhDynamicLocale"].get = jasmine.createSpy("get").and.returnValue(null);
- component["$translate"].use = jasmine.createSpy("use").and.returnValue("en");
-
- $rootScope.$emit("$localeChangeSuccess");
- expect(component["$translate"].use).toHaveBeenCalled();
- expect(component.changeLanguage).toHaveBeenCalledWith("en");
- done();
- });
- });
-});
diff --git a/src/app/components/translator/translator.service.ts b/src/app/components/translator/translator.service.ts
deleted file mode 100644
index c2ee0fa..0000000
--- a/src/app/components/translator/translator.service.ts
+++ /dev/null
@@ -1,59 +0,0 @@
-import {Injectable, Inject} from "ng-forward";
-
-@Injectable()
-@Inject("$translate", "tmhDynamicLocale", "amMoment", "angularLoad", "$rootScope")
-export class TranslatorService {
-
- availableLanguages: any;
-
- constructor(private $translate: angular.translate.ITranslateService,
- private tmhDynamicLocale: angular.dynamicLocale.tmhDynamicLocaleService,
- private amMoment: any,
- private angularLoad: any,
- private $rootScope: any) {
-
- this.$rootScope.$on("$localeChangeSuccess", () => {
- this.changeLanguage(tmhDynamicLocale.get() || $translate.use());
- });
- this.$rootScope.$on("$translateChangeSuccess", () => {
- this.configAvailableLanguages();
- });
- }
-
- currentLanguage() {
- return this.$translate.use();
- }
-
- changeLanguage(language: string) {
- if (!language) {
- console.log("WARN: language undefined");
- return;
- }
- this.changeMomentLocale(language);
- this.tmhDynamicLocale.set(language);
- this.angularLoad.loadScript(`/bower_components/messageformat/locale/${language}.js`).then(() => {
- return this.$translate.use(language);
- });
- }
-
- translate(text: string) {
- return this.$translate.instant(text);
- }
-
- private configAvailableLanguages() {
- this.availableLanguages = {
- "en": this.$translate.instant("language.en"),
- "pt": this.$translate.instant("language.pt")
- };
- }
-
- private changeMomentLocale(language: string) {
- let localePromise = Promise.resolve();
- if (language !== "en") {
- localePromise = this.angularLoad.loadScript(`/bower_components/moment/locale/${language}.js`);
- }
- localePromise.then(() => {
- this.amMoment.changeLocale(language);
- });
- }
-}
diff --git a/src/app/content-viewer/content-viewer-actions.component.spec.ts b/src/app/content-viewer/content-viewer-actions.component.spec.ts
deleted file mode 100644
index 35f9034..0000000
--- a/src/app/content-viewer/content-viewer-actions.component.spec.ts
+++ /dev/null
@@ -1,67 +0,0 @@
-import {providers} from 'ng-forward/cjs/testing/providers';
-
-import {Input, Component, provide} from 'ng-forward';
-
-import * as helpers from "../../spec/helpers";
-
-import {ComponentFixture} from 'ng-forward/cjs/testing/test-component-builder';
-import {ContentViewerActions} from './content-viewer-actions.component';
-
-// this htmlTemplate will be re-used between the container components in this spec file
-const htmlTemplate: string = ' ';
-
-describe('Content Viewer Actions Component', () => {
-
- beforeEach(() => {
-
- angular.mock.module("templates");
-
- providers((provide: any) => {
- return [
- provide('ProfileService', {
- useValue: helpers.mocks.profileService
- })
- ];
- });
- });
-
- let buildComponent = (): Promise => {
- return helpers.quickCreateComponent({
- providers: [
- helpers.provideEmptyObjects('Restangular'),
- helpers.provideFilters('translateFilter')
- ],
- directives: [ContentViewerActions],
- template: htmlTemplate
- });
- };
-
- it('renders content viewer actions directive', (done: Function) => {
- buildComponent().then((fixture: ComponentFixture) => {
- expect(fixture.debugElement.query('content-viewer-actions').length).toEqual(1);
-
- done();
- });
- });
-
- it('check if profile was loaded', (done: Function) => {
- let profile: any = {
- id: 1,
- identifier: 'the-profile-test',
- type: 'Person'
- };
-
- helpers.mocks.profileService.getCurrentProfile = () => {
- return helpers.mocks.promiseResultTemplate(profile);
- };
-
- buildComponent().then((fixture: ComponentFixture) => {
- let contentViewerComp: ContentViewerActions = fixture.debugElement.componentViewChildren[0].componentInstance;
-
- expect(contentViewerComp.profile).toEqual(jasmine.objectContaining(profile));
-
- done();
- });
- });
-
-});
diff --git a/src/app/content-viewer/content-viewer-actions.component.ts b/src/app/content-viewer/content-viewer-actions.component.ts
deleted file mode 100644
index a770e7c..0000000
--- a/src/app/content-viewer/content-viewer-actions.component.ts
+++ /dev/null
@@ -1,20 +0,0 @@
-import {Component, Inject, provide} from "ng-forward";
-import {ProfileService} from "../../lib/ng-noosfero-api/http/profile.service";
-
-@Component({
- selector: "content-viewer-actions",
- templateUrl: "app/content-viewer/navbar-actions.html",
- providers: [provide('profileService', { useClass: ProfileService })]
-})
-@Inject(ProfileService)
-export class ContentViewerActions {
-
- article: noosfero.Article;
- profile: noosfero.Profile;
-
- constructor(profileService: ProfileService) {
- profileService.getCurrentProfile().then((profile: noosfero.Profile) => {
- this.profile = profile;
- });
- }
-}
diff --git a/src/app/content-viewer/content-viewer.component.spec.ts b/src/app/content-viewer/content-viewer.component.spec.ts
deleted file mode 100644
index 175731e..0000000
--- a/src/app/content-viewer/content-viewer.component.spec.ts
+++ /dev/null
@@ -1,88 +0,0 @@
-import {providers} from 'ng-forward/cjs/testing/providers';
-
-import {Input, Component, provide} from 'ng-forward';
-
-import * as helpers from "../../spec/helpers";
-
-import {ComponentFixture} from 'ng-forward/cjs/testing/test-component-builder';
-import {ContentViewer} from './content-viewer.component';
-
-// this htmlTemplate will be re-used between the container components in this spec file
-const htmlTemplate: string = ' ';
-
-describe('Content Viewer Component', () => {
-
- let stateParamsService: any;
-
- // loading the templates
- beforeEach(() => {
- angular.mock.module("templates");
-
- stateParamsService = { page: 1 };
-
- providers((provide: any) => {
- return [
- provide('ArticleService', {
- useValue: helpers.mocks.articleService
- }),
- provide('ProfileService', {
- useValue: helpers.mocks.profileService
- }),
- // TODO: Como criar um mock do atributo "page" de stateParams
- provide('$stateParams', {
- useValue: stateParamsService
- })
- ];
- });
- });
-
- let buildComponent = (): Promise => {
- return helpers.quickCreateComponent({
- providers: [
- helpers.provideEmptyObjects('Restangular')
- ],
- directives: [ContentViewer],
- template: htmlTemplate
- });
- };
-
- it('renders content viewer directive', (done: Function) => {
- buildComponent().then((fixture: ComponentFixture) => {
- expect(fixture.debugElement.query('content-viewer').length).toEqual(1);
-
- done();
- });
- });
-
- it('check if article was loaded', (done: Function) => {
- let article: any = {
- id: 1,
- title: 'The article test'
- };
- let profile: any = {
- id: 1,
- identifier: 'the-profile-test',
- type: 'Person'
- };
-
- helpers.mocks.profileService.getCurrentProfile = () => {
- return helpers.mocks.promiseResultTemplate(profile);
- };
-
- helpers.mocks.articleService.getArticleByProfileAndPath = (profile: noosfero.Profile, path: string) => {
- return helpers.mocks.promiseResultTemplate({
- data: article
- });
- };
-
-
- buildComponent().then((fixture: ComponentFixture) => {
- let contentViewerComp: ContentViewer = fixture.debugElement.componentViewChildren[0].componentInstance;
-
- expect(contentViewerComp.profile).toEqual(profile);
- expect(contentViewerComp.article).toEqual(article);
-
- done();
- });
- });
-});
diff --git a/src/app/content-viewer/content-viewer.component.ts b/src/app/content-viewer/content-viewer.component.ts
deleted file mode 100644
index c7ca7fd..0000000
--- a/src/app/content-viewer/content-viewer.component.ts
+++ /dev/null
@@ -1,38 +0,0 @@
-import {ArticleView} from "../components/noosfero-articles/article/article_view";
-import {Input, Component, StateConfig, Inject, provide} from "ng-forward";
-
-import {ArticleBlog} from "./../components/noosfero-articles/blog/blog.component";
-import {ArticleService} from "../../lib/ng-noosfero-api/http/article.service";
-import {ProfileService} from "../../lib/ng-noosfero-api/http/profile.service";
-
-@Component({
- selector: "content-viewer",
- templateUrl: "app/content-viewer/page.html",
- directives: [ArticleBlog, ArticleView],
- providers: [
- provide('articleService', { useClass: ArticleService }),
- provide('profileService', { useClass: ProfileService })
- ]
-})
-@Inject(ArticleService, ProfileService, "$log", "$stateParams")
-export class ContentViewer {
-
- @Input()
- article: noosfero.Article = null;
-
- @Input()
- profile: noosfero.Profile = null;
-
- constructor(private articleService: ArticleService, private profileService: ProfileService, private $log: ng.ILogService, private $stateParams: angular.ui.IStateParamsService) {
- this.activate();
- }
-
- activate() {
- this.profileService.getCurrentProfile().then((profile: noosfero.Profile) => {
- this.profile = profile;
- return this.articleService.getArticleByProfileAndPath(this.profile, this.$stateParams["page"]);
- }).then((result: noosfero.RestResult) => {
- this.article = result.data;
- });
- }
-}
diff --git a/src/app/content-viewer/index.ts b/src/app/content-viewer/index.ts
deleted file mode 100644
index c9ffa0e..0000000
--- a/src/app/content-viewer/index.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-/* Module Index Entry - generated using the script npm run generate-index */
-export * from "./content-viewer-actions.component";
-export * from "./content-viewer.component";
diff --git a/src/app/content-viewer/navbar-actions.html b/src/app/content-viewer/navbar-actions.html
deleted file mode 100644
index 1b0af5e..0000000
--- a/src/app/content-viewer/navbar-actions.html
+++ /dev/null
@@ -1,7 +0,0 @@
-
diff --git a/src/app/content-viewer/page.html b/src/app/content-viewer/page.html
deleted file mode 100644
index 1c842e3..0000000
--- a/src/app/content-viewer/page.html
+++ /dev/null
@@ -1 +0,0 @@
-
diff --git a/src/app/index.run.ts b/src/app/index.run.ts
index 92cf02c..40d87d0 100644
--- a/src/app/index.run.ts
+++ b/src/app/index.run.ts
@@ -1,22 +1,22 @@
-import {Session} from "./components/auth/session";
-import {Notification} from "./components/notification/notification.component";
+import {SessionService} from "./login";
+import {NotificationService} from "./shared/services/notification.service";
/** @ngInject */
export function noosferoAngularRunBlock(
$log: ng.ILogService,
Restangular: restangular.IService,
- Session: Session,
- Notification: Notification
+ SessionService: SessionService,
+ NotificationService: NotificationService
) {
Restangular.addFullRequestInterceptor((element: any, operation: string, route: string, url: string, headers: string) => {
- if (Session.currentUser()) {
- (headers)["Private-Token"] = Session.currentUser().private_token;
+ if (SessionService.currentUser()) {
+ (headers)["Private-Token"] = SessionService.currentUser().private_token;
}
return { headers: headers };
});
Restangular.setErrorInterceptor((response: restangular.IResponse, deferred: ng.IDeferred) => {
// return false to break the promise chain and don't call catch
- return !Notification.httpError(response.status, response.data);
+ return !NotificationService.httpError(response.status, response.data);
});
}
diff --git a/src/app/index.ts b/src/app/index.ts
index 280d074..1b00440 100644
--- a/src/app/index.ts
+++ b/src/app/index.ts
@@ -5,10 +5,10 @@ import {noosferoAngularRunBlock} from "./index.run";
import {Main} from "./main/main.component";
import {bootstrap, bundle} from "ng-forward";
-import {AUTH_EVENTS} from "./components/auth/auth_events";
-import {AuthController} from "./components/auth/auth_controller";
+import {AUTH_EVENTS} from "./login/auth-events";
+import {AuthController} from "./login/auth.controller";
-import {Navbar} from "./components/navbar/navbar";
+import {Navbar} from "./layout/navbar/navbar";
declare var moment: any;
diff --git a/src/app/layout/blocks/block.component.spec.ts b/src/app/layout/blocks/block.component.spec.ts
new file mode 100644
index 0000000..0406fe5
--- /dev/null
+++ b/src/app/layout/blocks/block.component.spec.ts
@@ -0,0 +1,91 @@
+import {TestComponentBuilder} from 'ng-forward/cjs/testing/test-component-builder';
+import {Input, provide, Component} from 'ng-forward';
+
+import {BlockComponent} from './block.component';
+
+const tcb = new TestComponentBuilder();
+
+const htmlTemplate: string = ' ';
+
+describe("Components", () => {
+ describe("Block Component", () => {
+
+ // the karma preprocessor html2js transform the templates html into js files which put
+ // the templates to the templateCache into the module templates
+ // we need to load the module templates here as the template for the
+ // component Block will be load on our tests
+ beforeEach(angular.mock.module("templates"));
+
+ it("receives the block and the owner as inputs", done => {
+
+ // Creating a container component (BlockContainerComponent) to include
+ // the component under test (Block)
+ @Component({ selector: 'test-container-component', template: htmlTemplate, directives: [BlockComponent] })
+ class BlockContainerComponent {
+ block = { type: 'Block' };
+ owner = { name: 'profile-name' };
+ constructor() {
+ }
+ }
+
+ // uses the TestComponentBuilder instance to initialize the component
+ tcb
+ .createAsync(BlockContainerComponent).then(fixture => {
+ // and here we can inspect and run the test assertions
+ let myComponent: BlockComponent = fixture.componentInstance;
+
+ // assure the block object inside the Block matches
+ // the provided through the parent component
+ expect(myComponent.block.type).toEqual("Block");
+ expect(myComponent.owner.name).toEqual("profile-name");
+ done();
+ });
+ });
+
+
+ it("renders a component which matches to the block type", done => {
+ // CustomBlock component created to check if it will be used
+ // when a block with type 'CustomBlock' is provided to the noosfero-block (Block)
+ // *** Important *** - the selector is what ng-forward uses to define the name of the directive provider
+ @Component({ selector: 'noosfero-custom-block', template: "My Custom Block " })
+ class CustomBlock {
+ @Input() block: any;
+ @Input() owner: any;
+ }
+
+ @Component({ selector: 'test-container-component', template: htmlTemplate, directives: [BlockComponent, CustomBlock] })
+ class CustomBlockType {
+ block = { type: 'CustomBlock' };
+ owner = { name: 'profile-name' };
+ constructor() {
+ }
+ }
+ tcb
+ .createAsync(CustomBlockType).then(fixture => {
+ let myComponent: CustomBlockType = fixture.componentInstance;
+ expect(myComponent.block.type).toEqual("CustomBlock");
+ expect(fixture.debugElement.componentViewChildren[0].text()).toEqual("My Custom Block");
+ done();
+ });
+ });
+
+
+ it("renders the default block when hasn't defined a block type", done => {
+ @Component({ selector: 'test-container-component', template: htmlTemplate, directives: [BlockComponent] })
+ class CustomBlockType {
+ block: any = { type: null };
+ owner: any = { name: 'profile-name' };
+ constructor() {
+ }
+ }
+ tcb
+ .createAsync(CustomBlockType).then(fixture => {
+ let myComponent: CustomBlockType = fixture.componentInstance;
+ expect(myComponent.block.type).toBeNull();
+ expect(!!fixture.debugElement.nativeElement.querySelector("noosfero-default-block")).toBeTruthy();
+ done();
+ });
+ });
+
+ });
+});
\ No newline at end of file
diff --git a/src/app/layout/blocks/block.component.ts b/src/app/layout/blocks/block.component.ts
new file mode 100644
index 0000000..c139be4
--- /dev/null
+++ b/src/app/layout/blocks/block.component.ts
@@ -0,0 +1,20 @@
+import { Input, Inject, Component } from 'ng-forward';
+
+@Component({
+ selector: 'noosfero-block',
+ template: '
'
+})
+@Inject("$element", "$scope", "$injector", "$compile")
+export class BlockComponent {
+
+ @Input() block: any;
+ @Input() owner: any;
+
+ ngOnInit() {
+ let blockName = (this.block && this.block.type) ? this.block.type.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase() : "default-block";
+ this.$element.replaceWith(this.$compile(' ')(this.$scope));
+ }
+
+ constructor(private $element: any, private $scope: ng.IScope, private $injector: ng.auto.IInjectorService, private $compile: ng.ICompileService) {
+ }
+}
diff --git a/src/app/layout/blocks/block.scss b/src/app/layout/blocks/block.scss
new file mode 100644
index 0000000..f6df6ba
--- /dev/null
+++ b/src/app/layout/blocks/block.scss
@@ -0,0 +1,10 @@
+.block {
+ .panel-title {
+ font-size: 15px;
+ font-weight: bold;
+ }
+ .panel-heading {
+ background-color: transparent;
+ border: 0;
+ }
+}
diff --git a/src/app/layout/blocks/index.ts b/src/app/layout/blocks/index.ts
new file mode 100644
index 0000000..3f70547
--- /dev/null
+++ b/src/app/layout/blocks/index.ts
@@ -0,0 +1,2 @@
+/* Module Index Entry - generated using the script npm run generate-index */
+export * from "./block.component";
diff --git a/src/app/layout/blocks/link-list/index.ts b/src/app/layout/blocks/link-list/index.ts
new file mode 100644
index 0000000..765aba8
--- /dev/null
+++ b/src/app/layout/blocks/link-list/index.ts
@@ -0,0 +1,2 @@
+/* Module Index Entry - generated using the script npm run generate-index */
+export * from "./link-list.component";
diff --git a/src/app/layout/blocks/link-list/link-list.component.spec.ts b/src/app/layout/blocks/link-list/link-list.component.spec.ts
new file mode 100644
index 0000000..0de73a8
--- /dev/null
+++ b/src/app/layout/blocks/link-list/link-list.component.spec.ts
@@ -0,0 +1,65 @@
+import {TestComponentBuilder} from 'ng-forward/cjs/testing/test-component-builder';
+import {Pipe, Input, provide, Component} from 'ng-forward';
+import {provideFilters} from '../../../../spec/helpers';
+
+import {LinkListBlockComponent} from './link-list.component';
+
+const tcb = new TestComponentBuilder();
+
+const htmlTemplate: string = ' ';
+
+
+describe("Components", () => {
+
+ describe("Link List Block Component", () => {
+
+ beforeEach(angular.mock.module("templates"));
+
+ it("receives the block and the owner as inputs", done => {
+
+ // Creating a container component (BlockContainerComponent) to include
+ // the component under test (Block)
+ @Component({ selector: 'test-container-component', template: htmlTemplate, directives: [LinkListBlockComponent] })
+ class BlockContainerComponent {
+ block = { type: 'Block' };
+ owner = { name: 'profile-name' };
+ constructor() {
+ }
+ }
+
+ // uses the TestComponentBuilder instance to initialize the component
+ // .overrideView(LinkListBlock, { template: 'asdasdasd', pipes: [NoosferoTemplate] })
+ tcb.createAsync(BlockContainerComponent).then(fixture => {
+ // and here we can inspect and run the test assertions
+ let myComponent: LinkListBlockComponent = fixture.componentInstance;
+
+ // assure the block object inside the Block matches
+ // the provided through the parent component
+ expect(myComponent.block.type).toEqual("Block");
+ expect(myComponent.owner.name).toEqual("profile-name");
+ done();
+ });
+ });
+
+
+ it("display links stored in block settings", done => {
+
+ @Component({
+ selector: 'test-container-component',
+ template: htmlTemplate,
+ directives: [LinkListBlockComponent],
+ providers: provideFilters("noosferoTemplateFilter")
+ })
+ class CustomBlockType {
+ block: any = { settings: { links: [{ name: 'link1', address: 'address1' }, { name: 'link2', address: 'address2' }] } };
+ owner: any = { name: 'profile-name' };
+ }
+ tcb.createAsync(CustomBlockType).then(fixture => {
+ expect(fixture.debugElement.queryAll(".link-list-block a").length).toEqual(2);
+ done();
+ });
+ });
+
+ });
+
+});
\ No newline at end of file
diff --git a/src/app/layout/blocks/link-list/link-list.component.ts b/src/app/layout/blocks/link-list/link-list.component.ts
new file mode 100644
index 0000000..fa1ea80
--- /dev/null
+++ b/src/app/layout/blocks/link-list/link-list.component.ts
@@ -0,0 +1,20 @@
+import {Component, Input} from "ng-forward";
+
+@Component({
+ selector: "noosfero-link-list-block",
+ templateUrl: "app/layout/blocks/link-list/link-list.html"
+})
+export class LinkListBlockComponent {
+
+ @Input() block: any;
+ @Input() owner: any;
+
+ links: any;
+
+ ngOnInit() {
+ if (this.block && this.block.settings) {
+ this.links = this.block.settings.links;
+ }
+ }
+
+}
diff --git a/src/app/layout/blocks/link-list/link-list.html b/src/app/layout/blocks/link-list/link-list.html
new file mode 100644
index 0000000..17db1db
--- /dev/null
+++ b/src/app/layout/blocks/link-list/link-list.html
@@ -0,0 +1,7 @@
+
diff --git a/src/app/layout/blocks/link-list/link-list.scss b/src/app/layout/blocks/link-list/link-list.scss
new file mode 100644
index 0000000..bd60824
--- /dev/null
+++ b/src/app/layout/blocks/link-list/link-list.scss
@@ -0,0 +1,34 @@
+.icon-event {
+ @extend .fa-calendar;
+}
+.icon-photos {
+ @extend .fa-photo;
+}
+.icon-edit {
+ @extend .fa-edit;
+}
+.icon-ok {
+ @extend .fa-check;
+}
+.icon-send {
+ @extend .fa-send-o;
+}
+.icon-menu-people {
+ @extend .fa-user;
+}
+.icon-forum {
+ @extend .fa-users;
+}
+.icon-new {
+ @extend .fa-file-o;
+}
+.icon-save {
+ @extend .fa-save;
+}
+
+.link-list-block {
+ a i {
+ line-height: 25px;
+ color: #949494;
+ }
+}
diff --git a/src/app/layout/blocks/main-block/index.ts b/src/app/layout/blocks/main-block/index.ts
new file mode 100644
index 0000000..6a2e3e1
--- /dev/null
+++ b/src/app/layout/blocks/main-block/index.ts
@@ -0,0 +1,2 @@
+/* Module Index Entry - generated using the script npm run generate-index */
+export * from "./main-block.component";
diff --git a/src/app/layout/blocks/main-block/main-block.component.spec.ts b/src/app/layout/blocks/main-block/main-block.component.spec.ts
new file mode 100644
index 0000000..fd47bec
--- /dev/null
+++ b/src/app/layout/blocks/main-block/main-block.component.spec.ts
@@ -0,0 +1,40 @@
+import {TestComponentBuilder} from 'ng-forward/cjs/testing/test-component-builder';
+import {Input, provide, Component, StateConfig} from 'ng-forward';
+
+import {MainBlockComponent} from './main-block.component';
+import {NoosferoApp} from '../../../index.module';
+
+const tcb = new TestComponentBuilder();
+
+const htmlTemplate: string = ' ';
+
+describe("Components", () => {
+ describe("Main Block Component", () => {
+
+ // the karma preprocessor html2js transform the templates html into js files which put
+ // the templates to the templateCache into the module templates
+ // we need to load the module templates here as the template for the
+ // component Block will be load on our tests
+ beforeEach(angular.mock.module("templates"));
+
+ it("check if the main block has a tag with ui-view attribute", done => {
+
+ // Creating a container component (BlockContainerComponent) to include
+ // the component under test (Block)
+ @Component({ selector: 'test-container-component', template: htmlTemplate, directives: [MainBlockComponent] })
+ class BlockContainerComponent {
+ }
+
+ // uses the TestComponentBuilder instance to initialize the component
+ tcb.createAsync(BlockContainerComponent).then(fixture => {
+ // and here we can inspect and run the test assertions
+ // let myComponent: MainBlockComponent = fixture.componentInstance;
+
+ // assure the block object inside the Block matches
+ // the provided through the parent component
+ expect(fixture.debugElement.queryAll('[ui-view="mainBlockContent"]').length).toEqual(1);
+ done();
+ });
+ });
+ });
+});
\ No newline at end of file
diff --git a/src/app/layout/blocks/main-block/main-block.component.ts b/src/app/layout/blocks/main-block/main-block.component.ts
new file mode 100644
index 0000000..391d3a2
--- /dev/null
+++ b/src/app/layout/blocks/main-block/main-block.component.ts
@@ -0,0 +1,10 @@
+import {Component, Input} from 'ng-forward';
+import {BlockComponent} from '../block.component';
+
+@Component({
+ selector: 'noosfero-main-block',
+ templateUrl: 'app/layout/blocks/main-block/main-block.html'
+})
+export class MainBlockComponent {
+
+}
diff --git a/src/app/layout/blocks/main-block/main-block.html b/src/app/layout/blocks/main-block/main-block.html
new file mode 100644
index 0000000..129d0a2
--- /dev/null
+++ b/src/app/layout/blocks/main-block/main-block.html
@@ -0,0 +1 @@
+
diff --git a/src/app/layout/blocks/members-block/index.ts b/src/app/layout/blocks/members-block/index.ts
new file mode 100644
index 0000000..4da1eac
--- /dev/null
+++ b/src/app/layout/blocks/members-block/index.ts
@@ -0,0 +1,2 @@
+/* Module Index Entry - generated using the script npm run generate-index */
+export * from "./members-block.component";
diff --git a/src/app/layout/blocks/members-block/members-block.component.spec.ts b/src/app/layout/blocks/members-block/members-block.component.spec.ts
new file mode 100644
index 0000000..4bab067
--- /dev/null
+++ b/src/app/layout/blocks/members-block/members-block.component.spec.ts
@@ -0,0 +1,53 @@
+import {TestComponentBuilder} from 'ng-forward/cjs/testing/test-component-builder';
+import {Provider, Input, provide, Component} from 'ng-forward';
+
+import {MembersBlockComponent} from './members-block.component';
+
+const htmlTemplate: string = ' ';
+
+const tcb = new TestComponentBuilder();
+
+describe("Components", () => {
+ describe("Members Block Component", () => {
+
+ beforeEach(angular.mock.module("templates"));
+
+ let state = jasmine.createSpyObj("state", ["go"]);
+ let providers = [
+ new Provider('truncateFilter', { useValue: () => { } }),
+ new Provider('stripTagsFilter', { useValue: () => { } }),
+ new Provider('$state', { useValue: state }),
+ new Provider('ProfileService', {
+ useValue: {
+ getProfileMembers: (profileId: number, filters: any): any => {
+ return Promise.resolve({ data: { people: [{ identifier: "person1" }] } });
+ }
+ }
+ }),
+ ];
+ @Component({ selector: 'test-container-component', template: htmlTemplate, directives: [MembersBlockComponent], providers: providers })
+ class BlockContainerComponent {
+ block = { type: 'Block', settings: {} };
+ owner = { name: 'profile-name' };
+ constructor() {
+ }
+ }
+
+ it("get members of the block owner", done => {
+ tcb.createAsync(BlockContainerComponent).then(fixture => {
+ let block: MembersBlockComponent = fixture.debugElement.componentViewChildren[0].componentInstance;
+ expect(block.members).toEqual([{ identifier: "person1" }]);
+ done();
+ });
+ });
+
+ it("render the profile image for each member", done => {
+ tcb.createAsync(BlockContainerComponent).then(fixture => {
+ fixture.debugElement.getLocal("$rootScope").$apply();
+ expect(fixture.debugElement.queryAll("noosfero-profile-image").length).toEqual(1);
+ done();
+ });
+ });
+
+ });
+});
\ No newline at end of file
diff --git a/src/app/layout/blocks/members-block/members-block.component.ts b/src/app/layout/blocks/members-block/members-block.component.ts
new file mode 100644
index 0000000..99ec637
--- /dev/null
+++ b/src/app/layout/blocks/members-block/members-block.component.ts
@@ -0,0 +1,25 @@
+import {Input, Inject, Component} from "ng-forward";
+import {ProfileService} from "../../../../lib/ng-noosfero-api/http/profile.service";
+
+@Component({
+ selector: "noosfero-members-block",
+ templateUrl: 'app/layout/blocks/members-block/members-block.html',
+})
+@Inject(ProfileService)
+export class MembersBlockComponent {
+
+ @Input() block: noosfero.Block;
+ @Input() owner: noosfero.Profile;
+
+ members: any = [];
+
+ constructor(private profileService: ProfileService) {
+
+ }
+
+ ngOnInit() {
+ this.profileService.getProfileMembers(this.owner.id, { per_page: 6 }).then((response: any) => {
+ this.members = response.data.people;
+ });
+ }
+}
diff --git a/src/app/layout/blocks/members-block/members-block.html b/src/app/layout/blocks/members-block/members-block.html
new file mode 100644
index 0000000..913c149
--- /dev/null
+++ b/src/app/layout/blocks/members-block/members-block.html
@@ -0,0 +1,5 @@
+
diff --git a/src/app/layout/blocks/members-block/members-block.scss b/src/app/layout/blocks/members-block/members-block.scss
new file mode 100644
index 0000000..c5776e0
--- /dev/null
+++ b/src/app/layout/blocks/members-block/members-block.scss
@@ -0,0 +1,17 @@
+.members-block {
+ .member {
+ img, i.profile-image {
+ width: 60px;
+ }
+ img {
+ display: inline-block;
+ vertical-align: top;
+ }
+ i.profile-image {
+ text-align: center;
+ background-color: #889DB1;
+ color: #F1F1F1;
+ font-size: 4.5em;
+ }
+ }
+}
diff --git a/src/app/layout/blocks/profile-image-block/index.ts b/src/app/layout/blocks/profile-image-block/index.ts
new file mode 100644
index 0000000..4da4b46
--- /dev/null
+++ b/src/app/layout/blocks/profile-image-block/index.ts
@@ -0,0 +1,2 @@
+/* Module Index Entry - generated using the script npm run generate-index */
+export * from "./profile-image-block.component";
diff --git a/src/app/layout/blocks/profile-image-block/profile-image-block.component.spec.ts b/src/app/layout/blocks/profile-image-block/profile-image-block.component.spec.ts
new file mode 100644
index 0000000..42bf07a
--- /dev/null
+++ b/src/app/layout/blocks/profile-image-block/profile-image-block.component.spec.ts
@@ -0,0 +1,46 @@
+import {TestComponentBuilder, ComponentFixture} from 'ng-forward/cjs/testing/test-component-builder';
+import {Pipe, Input, provide, Component} from 'ng-forward';
+
+import {ProfileImageBlockComponent} from './profile-image-block.component';
+
+import * as helpers from "./../../../../spec/helpers";
+
+const tcb = new TestComponentBuilder();
+
+const htmlTemplate: string = ' ';
+
+describe("Components", () => {
+
+ describe("Profile Image Block Component", () => {
+
+ beforeEach(angular.mock.module("templates"));
+
+ @Component({
+ selector: 'test-container-component',
+ template: htmlTemplate,
+ directives: [ProfileImageBlockComponent],
+ providers: helpers.provideFilters("translateFilter")
+ })
+ class BlockContainerComponent {
+ block = { type: 'Block' };
+ owner = { name: 'profile-name' };
+ constructor() {
+ }
+ }
+
+ it("show image if present", () => {
+ helpers.tcb.createAsync(BlockContainerComponent).then(fixture => {
+ let elProfile = fixture.debugElement.componentViewChildren[0];
+ expect(elProfile.query('div.profile-image-block').length).toEqual(1);
+ });
+ });
+
+ it("has link to the profile", () => {
+ helpers.tcb.createAsync(BlockContainerComponent).then(fixture => {
+ let elProfile = fixture.debugElement.componentViewChildren[0];
+ expect(elProfile.query('a.settings-link').length).toEqual(1);
+ });
+ });
+
+ });
+});
diff --git a/src/app/layout/blocks/profile-image-block/profile-image-block.component.ts b/src/app/layout/blocks/profile-image-block/profile-image-block.component.ts
new file mode 100644
index 0000000..c13fed2
--- /dev/null
+++ b/src/app/layout/blocks/profile-image-block/profile-image-block.component.ts
@@ -0,0 +1,14 @@
+import {Inject, Input, Component} from "ng-forward";
+import {ProfileImageComponent} from "./../../../profile/image/image.component";
+
+@Component({
+ selector: "noosfero-profile-image-block",
+ templateUrl: 'app/layout/blocks/profile-image-block/profile-image-block.html',
+ directives: [ProfileImageComponent]
+})
+export class ProfileImageBlockComponent {
+
+ @Input() block: noosfero.Block;
+ @Input() owner: noosfero.Profile;
+
+}
diff --git a/src/app/layout/blocks/profile-image-block/profile-image-block.html b/src/app/layout/blocks/profile-image-block/profile-image-block.html
new file mode 100644
index 0000000..f9159e3
--- /dev/null
+++ b/src/app/layout/blocks/profile-image-block/profile-image-block.html
@@ -0,0 +1,6 @@
+
diff --git a/src/app/layout/blocks/profile-image-block/profile-image-block.scss b/src/app/layout/blocks/profile-image-block/profile-image-block.scss
new file mode 100644
index 0000000..a609250
--- /dev/null
+++ b/src/app/layout/blocks/profile-image-block/profile-image-block.scss
@@ -0,0 +1,5 @@
+.profile-image-block {
+ .settings-link {
+ display: block;
+ }
+}
diff --git a/src/app/layout/blocks/raw-html/index.ts b/src/app/layout/blocks/raw-html/index.ts
new file mode 100644
index 0000000..477ef35
--- /dev/null
+++ b/src/app/layout/blocks/raw-html/index.ts
@@ -0,0 +1,2 @@
+/* Module Index Entry - generated using the script npm run generate-index */
+export * from "./raw-html.component";
diff --git a/src/app/layout/blocks/raw-html/raw-html.component.spec.ts b/src/app/layout/blocks/raw-html/raw-html.component.spec.ts
new file mode 100644
index 0000000..7ec81ed
--- /dev/null
+++ b/src/app/layout/blocks/raw-html/raw-html.component.spec.ts
@@ -0,0 +1,36 @@
+import {TestComponentBuilder} from 'ng-forward/cjs/testing/test-component-builder';
+import {Component} from 'ng-forward';
+
+import {RawHTMLBlockComponent} from './raw-html.component';
+
+const tcb = new TestComponentBuilder();
+
+const htmlTemplate: string = ' ';
+
+describe("Components", () => {
+
+ describe("Raw Html Block Component", () => {
+
+ beforeEach(angular.mock.module("templates"));
+ beforeEach(angular.mock.module("ngSanitize"));
+
+ it("display html stored in block settings", done => {
+
+ @Component({
+ selector: 'test-container-component',
+ template: htmlTemplate,
+ directives: [RawHTMLBlockComponent],
+ })
+ class CustomBlockType {
+ block: any = { settings: { html: 'block content ' } };
+ owner: any = { name: 'profile-name' };
+ }
+ tcb.createAsync(CustomBlockType).then(fixture => {
+ expect(fixture.debugElement.query(".raw-html-block em").text().trim()).toEqual('block content');
+ done();
+ });
+ });
+
+ });
+
+});
diff --git a/src/app/layout/blocks/raw-html/raw-html.component.ts b/src/app/layout/blocks/raw-html/raw-html.component.ts
new file mode 100644
index 0000000..b320d98
--- /dev/null
+++ b/src/app/layout/blocks/raw-html/raw-html.component.ts
@@ -0,0 +1,18 @@
+import {Component, Input} from "ng-forward";
+
+@Component({
+ selector: "noosfero-raw-htmlblock",
+ templateUrl: 'app/layout/blocks/raw-html/raw-html.html'
+})
+
+export class RawHTMLBlockComponent {
+
+ @Input() block: any;
+ @Input() owner: any;
+
+ html: string;
+
+ ngOnInit() {
+ this.html = this.block.settings.html;
+ }
+}
diff --git a/src/app/layout/blocks/raw-html/raw-html.html b/src/app/layout/blocks/raw-html/raw-html.html
new file mode 100644
index 0000000..af6cf33
--- /dev/null
+++ b/src/app/layout/blocks/raw-html/raw-html.html
@@ -0,0 +1,2 @@
+
+
diff --git a/src/app/layout/blocks/recent-documents/index.ts b/src/app/layout/blocks/recent-documents/index.ts
new file mode 100644
index 0000000..875a233
--- /dev/null
+++ b/src/app/layout/blocks/recent-documents/index.ts
@@ -0,0 +1,2 @@
+/* Module Index Entry - generated using the script npm run generate-index */
+export * from "./recent-documents.component";
diff --git a/src/app/layout/blocks/recent-documents/recent-documents.component.spec.ts b/src/app/layout/blocks/recent-documents/recent-documents.component.spec.ts
new file mode 100644
index 0000000..6125633
--- /dev/null
+++ b/src/app/layout/blocks/recent-documents/recent-documents.component.spec.ts
@@ -0,0 +1,80 @@
+import {TestComponentBuilder} from 'ng-forward/cjs/testing/test-component-builder';
+import {Provider, Input, provide, Component} from 'ng-forward';
+import {provideFilters} from '../../../../spec/helpers';
+import {RecentDocumentsBlockComponent} from './recent-documents.component';
+
+const htmlTemplate: string = ' ';
+
+const tcb = new TestComponentBuilder();
+
+describe("Components", () => {
+ describe("Recent Documents Block Component", () => {
+
+ let settingsObj = {};
+ let mockedArticleService = {
+ getByProfile: (profile: noosfero.Profile, filters: any): any => {
+ return Promise.resolve({ data: [{ name: "article1" }], headers: (name: string) => { return name; } });
+ }
+ };
+ let profile = { name: 'profile-name' };
+ beforeEach(angular.mock.module("templates"));
+
+ let state = jasmine.createSpyObj("state", ["go"]);
+
+
+ function getProviders() {
+ return [
+ new Provider('$state', { useValue: state }),
+ new Provider('ArticleService', {
+ useValue: mockedArticleService
+ }),
+ ].concat(provideFilters("truncateFilter", "stripTagsFilter"));
+ }
+ let componentClass: any = null;
+
+ function getComponent() {
+ @Component({ selector: 'test-container-component', template: htmlTemplate, directives: [RecentDocumentsBlockComponent], providers: getProviders() })
+ class BlockContainerComponent {
+ block = { type: 'Block', settings: settingsObj };
+ owner = profile;
+ constructor() {
+ }
+ }
+ return BlockContainerComponent;
+ }
+
+
+ it("get recent documents from the article service", done => {
+ tcb.createAsync(getComponent()).then(fixture => {
+ let recentDocumentsBlock: RecentDocumentsBlockComponent = fixture.debugElement.componentViewChildren[0].componentInstance;
+ expect(recentDocumentsBlock.documents).toEqual([{ name: "article1" }]);
+ done();
+ });
+ });
+
+ it("go to article page when open a document", done => {
+ tcb.createAsync(getComponent()).then(fixture => {
+ let recentDocumentsBlock: RecentDocumentsBlockComponent = fixture.debugElement.componentViewChildren[0].componentInstance;
+ recentDocumentsBlock.openDocument({ path: "path", profile: { identifier: "identifier" } });
+ expect(state.go).toHaveBeenCalledWith("main.profile.page", { page: "path", profile: "identifier" });
+ done();
+ });
+ });
+
+ it("it uses default limit 5 if not defined on block", done => {
+ settingsObj = null;
+ mockedArticleService = jasmine.createSpyObj("mockedArticleService", ["getByProfile"]);
+ (mockedArticleService).mocked = true;
+ let thenMocked = jasmine.createSpy("then");
+ mockedArticleService.getByProfile = jasmine.createSpy("getByProfile").and.returnValue({then: thenMocked});
+ let getByProfileFunct = mockedArticleService.getByProfile;
+ tcb.createAsync(getComponent()).then(fixture => {
+ let recentDocumentsBlock: RecentDocumentsBlockComponent = fixture.debugElement.componentViewChildren[0].componentInstance;
+ recentDocumentsBlock.openDocument({ path: "path", profile: { identifier: "identifier" } });
+ expect(getByProfileFunct).toHaveBeenCalledWith(profile, { content_type: 'TinyMceArticle', per_page: 5 });
+ done();
+ });
+ });
+
+ });
+});
\ No newline at end of file
diff --git a/src/app/layout/blocks/recent-documents/recent-documents.component.ts b/src/app/layout/blocks/recent-documents/recent-documents.component.ts
new file mode 100644
index 0000000..ac18d68
--- /dev/null
+++ b/src/app/layout/blocks/recent-documents/recent-documents.component.ts
@@ -0,0 +1,41 @@
+import {Component, Inject, Input} from "ng-forward";
+import {ArticleService} from "../../../../lib/ng-noosfero-api/http/article.service";
+
+@Component({
+ selector: "noosfero-recent-documents-block",
+ templateUrl: 'app/layout/blocks/recent-documents/recent-documents.html'
+})
+@Inject(ArticleService, "$state")
+export class RecentDocumentsBlockComponent {
+
+ @Input() block: any;
+ @Input() owner: any;
+
+ profile: any;
+ documents: any;
+
+ documentsLoaded: boolean = false;
+
+ constructor(private articleService: ArticleService, private $state: any) {
+ }
+
+ ngOnInit() {
+ this.profile = this.owner;
+ this.documents = [];
+
+ let limit = ((this.block && this.block.settings) ? this.block.settings.limit : null) || 5;
+ // FIXME get all text articles
+ // FIXME make the getByProfile a generic method where we tell the type passing a class TinyMceArticle
+ // and the promise should be of type TinyMceArticle[], per example
+ this.articleService.getByProfile(this.profile, { content_type: 'TinyMceArticle', per_page: limit })
+ .then((result: noosfero.RestResult) => {
+ this.documents = result.data;
+ this.documentsLoaded = true;
+ });
+ }
+
+ openDocument(article: any) {
+ this.$state.go("main.profile.page", { page: article.path, profile: article.profile.identifier });
+ }
+
+}
diff --git a/src/app/layout/blocks/recent-documents/recent-documents.html b/src/app/layout/blocks/recent-documents/recent-documents.html
new file mode 100644
index 0000000..1421cfe
--- /dev/null
+++ b/src/app/layout/blocks/recent-documents/recent-documents.html
@@ -0,0 +1,18 @@
+
diff --git a/src/app/layout/blocks/recent-documents/recent-documents.scss b/src/app/layout/blocks/recent-documents/recent-documents.scss
new file mode 100644
index 0000000..74cf5e9
--- /dev/null
+++ b/src/app/layout/blocks/recent-documents/recent-documents.scss
@@ -0,0 +1,65 @@
+.block.recentdocumentsblock {
+ .deckgrid[deckgrid]::before {
+ font-size: 0; /* See https://github.com/akoenig/angular-deckgrid/issues/14#issuecomment-35728861 */
+ visibility: hidden;
+ }
+ .author {
+ img {
+ width: 30px;
+ height: 30px;
+ }
+ }
+ .header {
+ .subheader {
+ color: #C1C1C1;
+ font-size: 10px;
+ }
+ }
+ .post-lead {
+ color: #8E8E8E;
+ font-size: 14px;
+ }
+ .article-image {
+ margin: 10px 0;
+ }
+}
+
+.col-md-2-5 {
+ .deckgrid[deckgrid]::before {
+ content: '1 .deck-column';
+ }
+}
+
+.col-md-7 {
+ .block.recentdocumentsblock {
+ background-color: transparent;
+ border: 0;
+
+ .deckgrid[deckgrid]::before {
+ content: '3 .deck-column';
+ }
+
+ .panel-heading {
+ display: none;
+ }
+ .panel-body {
+ padding: 0;
+ }
+
+ .deckgrid {
+ .column {
+ float: left;
+ }
+
+ .deck-column {
+ @extend .col-md-4;
+ padding: 0;
+
+ .a-card {
+ padding: 10px;
+ margin: 3px;
+ }
+ }
+ }
+ }
+}
diff --git a/src/app/layout/boxes/box.html b/src/app/layout/boxes/box.html
new file mode 100644
index 0000000..4550503
--- /dev/null
+++ b/src/app/layout/boxes/box.html
@@ -0,0 +1,10 @@
+
+
+
+
{{block.title}}
+
+
+
+
+
+
diff --git a/src/app/layout/boxes/boxes.component.spec.ts b/src/app/layout/boxes/boxes.component.spec.ts
new file mode 100644
index 0000000..6d6602c
--- /dev/null
+++ b/src/app/layout/boxes/boxes.component.spec.ts
@@ -0,0 +1,65 @@
+import {Component} from 'ng-forward';
+
+import {BoxesComponent} from './boxes.component';
+
+import {
+ createComponentFromClass,
+ quickCreateComponent,
+ provideEmptyObjects,
+ createProviderToValue,
+ getAngularServiceFactory,
+ provideFilters
+} from "../../../spec/helpers";
+
+// this htmlTemplate will be re-used between the container components in this spec file
+const htmlTemplate: string = '';
+
+
+describe("Boxes Component", () => {
+
+ beforeEach(() => {
+ angular.mock.module("templates");
+ });
+
+ @Component({
+ selector: 'test-container-component',
+ template: htmlTemplate,
+ directives: [BoxesComponent],
+ providers: []
+ })
+ class BoxesContainerComponent {
+ boxes: noosfero.Box[] = [
+ { id: 1, position: 1 },
+ { id: 2, position: 2 }
+ ];
+
+ owner: noosfero.Profile = {
+ id: 1,
+ identifier: 'profile-name',
+ type: 'Person'
+ };
+ }
+
+ it("renders boxes into a container", (done: Function) => {
+ createComponentFromClass(BoxesContainerComponent).then((fixture) => {
+ let boxesHtml = fixture.debugElement;
+ expect(boxesHtml.query('div.col-md-7').length).toEqual(1);
+ expect(boxesHtml.query('div.col-md-2-5').length).toEqual(1);
+
+ done();
+ });
+ });
+
+ it("check the boxes order", (done: Function) => {
+ createComponentFromClass(BoxesContainerComponent).then((fixture) => {
+
+ let boxesComponent: BoxesComponent = fixture.debugElement.componentViewChildren[0].componentInstance;
+ let boxesContainer: BoxesContainerComponent = fixture.componentInstance;
+
+ expect(boxesComponent.boxesOrder(boxesContainer.boxes[0])).toEqual(1);
+ expect(boxesComponent.boxesOrder(boxesContainer.boxes[1])).toEqual(0);
+
+ done();
+ });
+ });
+});
diff --git a/src/app/layout/boxes/boxes.component.ts b/src/app/layout/boxes/boxes.component.ts
new file mode 100644
index 0000000..75d41ab
--- /dev/null
+++ b/src/app/layout/boxes/boxes.component.ts
@@ -0,0 +1,16 @@
+import {Input, Inject, Component} from 'ng-forward';
+
+@Component({
+ selector: "noosfero-boxes",
+ templateUrl: "app/layout/boxes/boxes.html"
+})
+export class BoxesComponent {
+
+ @Input() boxes: noosfero.Box[];
+ @Input() owner: noosfero.Profile;
+
+ boxesOrder(box: noosfero.Box) {
+ if (box.position === 2) return 0;
+ return box.position;
+ }
+}
diff --git a/src/app/layout/boxes/boxes.html b/src/app/layout/boxes/boxes.html
new file mode 100644
index 0000000..5478806
--- /dev/null
+++ b/src/app/layout/boxes/boxes.html
@@ -0,0 +1 @@
+
diff --git a/src/app/layout/boxes/boxes.scss b/src/app/layout/boxes/boxes.scss
new file mode 100644
index 0000000..9e6d526
--- /dev/null
+++ b/src/app/layout/boxes/boxes.scss
@@ -0,0 +1,6 @@
+.col-md-2-5 {
+ @extend .col-md-3;
+ @media (min-width: 920px) {
+ width: 20.83%;
+ }
+}
diff --git a/src/app/layout/boxes/index.ts b/src/app/layout/boxes/index.ts
new file mode 100644
index 0000000..6369864
--- /dev/null
+++ b/src/app/layout/boxes/index.ts
@@ -0,0 +1,2 @@
+/* Module Index Entry - generated using the script npm run generate-index */
+export * from "./boxes.component";
diff --git a/src/app/layout/index.ts b/src/app/layout/index.ts
new file mode 100644
index 0000000..4206e70
--- /dev/null
+++ b/src/app/layout/index.ts
@@ -0,0 +1 @@
+/* Module Index Entry - generated using the script npm run generate-index */
diff --git a/src/app/layout/language-selector/index.ts b/src/app/layout/language-selector/index.ts
new file mode 100644
index 0000000..816be3d
--- /dev/null
+++ b/src/app/layout/language-selector/index.ts
@@ -0,0 +1,2 @@
+/* Module Index Entry - generated using the script npm run generate-index */
+export * from "./language-selector.component";
diff --git a/src/app/layout/language-selector/language-selector.component.spec.ts b/src/app/layout/language-selector/language-selector.component.spec.ts
new file mode 100644
index 0000000..b20e9e3
--- /dev/null
+++ b/src/app/layout/language-selector/language-selector.component.spec.ts
@@ -0,0 +1,46 @@
+import {ComponentFixture} from 'ng-forward/cjs/testing/test-component-builder';
+import {provide} from 'ng-forward';
+
+import {LanguageSelectorService} from './language-selector.component';
+
+import * as helpers from "../../../spec/helpers";
+
+describe("Components", () => {
+
+ describe("Language Selector Component", () => {
+
+ beforeEach(angular.mock.module("templates"));
+
+ let translatorService: any;
+
+ let buildComponent = (): Promise => {
+ translatorService = jasmine.createSpyObj("translatorService", ["availableLanguages", "currentLanguage"]);
+ return helpers.quickCreateComponent({
+ template: " ",
+ directives: [LanguageSelectorService],
+ providers: [
+ provide('TranslatorService', {
+ useValue: translatorService
+ })
+ ].concat(helpers.provideFilters("translateFilter"))
+ });
+ };
+
+ it("display language options", (done) => {
+ buildComponent().then(fixture => {
+ fixture.debugElement.getLocal("$rootScope").$apply();
+ expect(fixture.debugElement.queryAll('li.language').length).toEqual(2);
+ done();
+ });
+ });
+
+ it("call the translator service when change the language", (done) => {
+ let translatorService = jasmine.createSpyObj("translatorService", ["changeLanguage"]);
+ let languageSelector = new LanguageSelectorService(translatorService);
+ languageSelector.changeLanguage("en");
+ expect(translatorService.changeLanguage).toHaveBeenCalledWith("en");
+ done();
+ });
+
+ });
+});
diff --git a/src/app/layout/language-selector/language-selector.component.ts b/src/app/layout/language-selector/language-selector.component.ts
new file mode 100644
index 0000000..41bc805
--- /dev/null
+++ b/src/app/layout/language-selector/language-selector.component.ts
@@ -0,0 +1,24 @@
+import {Component, Inject} from "ng-forward";
+import {TranslatorService} from "../../shared/services/translator.service";
+
+@Component({
+ selector: "language-selector",
+ templateUrl: "app/layout/language-selector/language-selector.html"
+})
+@Inject(TranslatorService)
+export class LanguageSelectorService {
+
+ constructor(private translatorService: TranslatorService) { }
+
+ currentLanguage() {
+ return this.translatorService.currentLanguage();
+ }
+
+ changeLanguage(language: string) {
+ this.translatorService.changeLanguage(language);
+ }
+
+ availableLanguages() {
+ return this.translatorService.availableLanguages;
+ }
+}
diff --git a/src/app/layout/language-selector/language-selector.html b/src/app/layout/language-selector/language-selector.html
new file mode 100644
index 0000000..9499df5
--- /dev/null
+++ b/src/app/layout/language-selector/language-selector.html
@@ -0,0 +1,13 @@
+
diff --git a/src/app/layout/navbar/index.ts b/src/app/layout/navbar/index.ts
new file mode 100644
index 0000000..dd56b10
--- /dev/null
+++ b/src/app/layout/navbar/index.ts
@@ -0,0 +1,2 @@
+/* Module Index Entry - generated using the script npm run generate-index */
+export * from "./navbar";
diff --git a/src/app/layout/navbar/navbar.directive.spec.js b/src/app/layout/navbar/navbar.directive.spec.js
new file mode 100644
index 0000000..2f89fad
--- /dev/null
+++ b/src/app/layout/navbar/navbar.directive.spec.js
@@ -0,0 +1,45 @@
+(function() {
+ 'use strict';
+
+ describe('directive navbar', function() {
+ var vm;
+ var el;
+ var AUTH_EVENTS;
+ var $state;
+
+ beforeEach(module('angular'));
+ beforeEach(inject(function($compile, $rootScope, $httpBackend, _AUTH_EVENTS_, _$state_) {
+ $state = _$state_;
+ AUTH_EVENTS = _AUTH_EVENTS_;
+ $httpBackend.when('POST','/api/v1/login_from_cookie').respond({});
+
+ el = angular.element(' ');
+
+ $compile(el)($rootScope.$new());
+ $rootScope.$digest();
+ vm = el.isolateScope().vm;
+ }));
+
+ it('should be compiled', function() {
+ expect(el.html()).not.toEqual(null);
+ });
+
+ it('should have isolate scope object with instanciate members', function() {
+ expect(vm).toEqual(jasmine.any(Object));
+ expect(vm.currentUser).toEqual(undefined);
+ });
+
+ it('should reload current state after login', function() {
+ spyOn($state, 'go');
+ el.isolateScope().$broadcast(AUTH_EVENTS.loginSuccess, {});
+ expect($state.go).toHaveBeenCalled();
+ });
+
+ it('should open login when not logged in', function() {
+ spyOn(vm, 'openLogin');
+ vm.activate();
+ expect(vm.openLogin).toHaveBeenCalled();
+ });
+
+ });
+})();
diff --git a/src/app/layout/navbar/navbar.html b/src/app/layout/navbar/navbar.html
new file mode 100644
index 0000000..ed5742f
--- /dev/null
+++ b/src/app/layout/navbar/navbar.html
@@ -0,0 +1,49 @@
+
+
+
diff --git a/src/app/layout/navbar/navbar.scss b/src/app/layout/navbar/navbar.scss
new file mode 100644
index 0000000..5809fab
--- /dev/null
+++ b/src/app/layout/navbar/navbar.scss
@@ -0,0 +1,31 @@
+.navbar {
+
+ .container-fluid {
+ padding-right: 12%;
+ padding-left: 12%;
+ @media (max-width: 978px) {
+ padding-right: 2%;
+ padding-left: 2%;
+ }
+
+ .navbar-brand {
+ .noosfero-logo img {
+ height: 35px;
+ }
+ }
+
+ .navbar-nav {
+ .profile-menu .profile-image {
+ img {
+ height: 30px;
+ width: 30px;
+ display: inline-block;
+ @extend .img-circle;
+ }
+ i {
+ font-size: 1.7em;
+ }
+ }
+ }
+ }
+}
diff --git a/src/app/layout/navbar/navbar.spec.ts b/src/app/layout/navbar/navbar.spec.ts
new file mode 100644
index 0000000..95adfe0
--- /dev/null
+++ b/src/app/layout/navbar/navbar.spec.ts
@@ -0,0 +1,187 @@
+import * as helpers from "./../../../spec/helpers";
+import {Navbar} from "./navbar";
+
+import {Injectable, Provider, provide} from "ng-forward";
+
+import {ComponentFixture} from 'ng-forward/cjs/testing/test-component-builder';
+
+import {SessionService, AuthService, AuthController, IAuthEvents, AUTH_EVENTS} from "./../../login";
+
+
+describe("Components", () => {
+
+ describe("Navbar Component", () => {
+
+ let user: noosfero.User = null;
+ let scope: any;
+ let $rootScope: ng.IRootScopeService;
+
+ let modalInstance: any;
+ let $modal: any;
+ let authService: any;
+ let stateService: any;
+ let sessionService: SessionService;
+
+ let provideFunc = provide;
+
+ // before Each -> loading mocks on locals variables
+ beforeEach(() => {
+ user = {
+ id: 1,
+ login: "user"
+ };
+ scope = helpers.mocks.scopeWithEvents;
+ modalInstance = helpers.mocks.modalInstance;
+ $modal = helpers.mocks.$modal;
+ authService = helpers.mocks.authService;
+ stateService = jasmine.createSpyObj("$state", ["go"]);
+ sessionService = helpers.mocks.sessionWithCurrentUser(user);
+ });
+
+
+ // loading the templates
+ beforeEach(angular.mock.module("templates"));
+
+
+ // this function allow build the fixture of the container component
+ // and is reused in each test
+ // The main idea behing not prebuild it on a general beforeEach block is
+ // to allow tests configure the mock services accordilly their own needs
+ let buildComponent = (): Promise => {
+ return helpers.quickCreateComponent({
+ providers: [
+ provide('$modal', {
+ useValue: $modal
+ }),
+ provide('AuthService', {
+ useValue: authService
+ }),
+ helpers.provideEmptyObjects('moment'),
+ provide('$state', {
+ useValue: stateService
+ }),
+ provide("$scope", {
+ useValue: scope
+ }),
+ provide('SessionService', {
+ useValue: sessionService
+ }),
+ provide('AUTH_EVENTS', {
+ useValue: {
+ AUTH_EVENTS
+ }
+ }),
+ provide('TranslatorService', {
+ useValue: helpers.mocks.translatorService
+ })
+ ].concat(helpers.provideFilters("translateFilter")),
+ directives: [Navbar],
+ template: ' '
+ });
+ };
+
+
+ it('should get the loggedIn user', (done: Function) => {
+ buildComponent().then((fixture: ComponentFixture) => {
+ let navbarInstance: Navbar = fixture.debugElement.componentViewChildren[0].componentInstance;
+ expect(navbarInstance).toBeDefined();
+ expect(navbarInstance["currentUser"]).toEqual(user);
+ done();
+ });
+ });
+
+ it('should open on click', (done: Function) => {
+ spyOn($modal, "open");
+ buildComponent().then((fixture: ComponentFixture) => {
+ let navbarComp: Navbar = fixture.debugElement.componentViewChildren[0].componentInstance;
+ navbarComp.openLogin();
+ expect($modal.open).toHaveBeenCalled();
+ expect($modal.open).toHaveBeenCalledWith({
+ templateUrl: 'app/components/auth/login.html',
+ controller: AuthController,
+ controllerAs: 'vm',
+ bindToController: true
+ });
+ done();
+ });
+ });
+
+ it('should logout', (done: Function) => {
+ buildComponent().then((fixture: ComponentFixture) => {
+ let navbarComp: Navbar = fixture.debugElement.componentViewChildren[0].componentInstance;
+ spyOn(authService, "logout");
+ try {
+ navbarComp.logout();
+ expect(authService.logout).toHaveBeenCalled();
+ done();
+ } catch (e) {
+ console.error(e);
+ fail(e.message);
+ done();
+ }
+ });
+ });
+
+
+ it('should not activate user when logged in', (done: Function) => {
+ buildComponent().then((fixture: ComponentFixture) => {
+ let navbarComp: Navbar = fixture.debugElement.componentViewChildren[0].componentInstance;
+ spyOn(navbarComp, "openLogin");
+ navbarComp.activate();
+ expect((navbarComp.openLogin).calls.count()).toBe(0);
+ done();
+ });
+ });
+
+ it('should activate when user not logged in', (done: Function) => {
+ spyOn(sessionService, 'currentUser').and.returnValue(null);
+ buildComponent().then((fixture: ComponentFixture) => {
+ let navbarComp: Navbar = fixture.debugElement.componentViewChildren[0].componentInstance;
+ spyOn(navbarComp, "openLogin");
+ navbarComp.activate();
+ expect(navbarComp.openLogin).toHaveBeenCalled();
+ done();
+ });
+ });
+
+
+ it('closes the modal after login', (done: Function) => {
+ modalInstance = jasmine.createSpyObj("modalInstance", ["close"]);
+ modalInstance.close = jasmine.createSpy("close");
+
+ $modal.open = () => {
+ return modalInstance;
+ };
+
+ buildComponent().then((fixture: ComponentFixture) => {
+ let navbarComp: Navbar = fixture.debugElement.componentViewChildren[0].componentInstance;
+ let localScope: ng.IScope = navbarComp["$scope"];
+
+ navbarComp.openLogin();
+ localScope.$emit(AUTH_EVENTS.loginSuccess);
+ expect(modalInstance.close).toHaveBeenCalled();
+ done();
+ });
+ });
+
+ it('updates current user on logout', (done: Function) => {
+ buildComponent().then((fixture: ComponentFixture) => {
+ let navbarComp: Navbar = fixture.debugElement.componentViewChildren[0].componentInstance;
+ let localScope: ng.IScope = navbarComp["$scope"];
+
+ // init navbar currentUser with some user
+ navbarComp["currentUser"] = user;
+
+ // changes the current User to return null,
+ // and emmit the 'logoutSuccess' event
+ // just what happens when user logsout
+ sessionService.currentUser = () => { return null; };
+ localScope.$emit(AUTH_EVENTS.logoutSuccess);
+ expect(navbarComp["currentUser"]).toBeNull();
+ done();
+ });
+ });
+
+
+ });
+});
diff --git a/src/app/layout/navbar/navbar.ts b/src/app/layout/navbar/navbar.ts
new file mode 100644
index 0000000..f1db8b3
--- /dev/null
+++ b/src/app/layout/navbar/navbar.ts
@@ -0,0 +1,66 @@
+import {Component, Inject} from "ng-forward";
+import {LanguageSelectorService} from "../language-selector/language-selector.component";
+
+
+import {SessionService, AuthService, AuthController, IAuthEvents, AUTH_EVENTS} from "./../../login";
+
+@Component({
+ selector: "acme-navbar",
+ templateUrl: "app/layout/navbar/navbar.html",
+ directives: [LanguageSelectorService],
+ providers: [AuthService, SessionService]
+})
+@Inject("$modal", AuthService, "SessionService", "$scope", "$state")
+export class Navbar {
+
+ private currentUser: noosfero.User;
+ private modalInstance: any = null;
+ /**
+ *
+ */
+ constructor(
+ private $modal: any,
+ private authService: AuthService,
+ private session: SessionService,
+ private $scope: ng.IScope,
+ private $state: ng.ui.IStateService
+ ) {
+ this.currentUser = this.session.currentUser();
+
+ this.$scope.$on(AUTH_EVENTS.loginSuccess, () => {
+ if (this.modalInstance) {
+ this.modalInstance.close();
+ this.modalInstance = null;
+ }
+
+ this.$state.go(this.$state.current, {}, { reload: true }); // TODO move to auth
+ });
+
+ this.$scope.$on(AUTH_EVENTS.logoutSuccess, () => {
+ this.currentUser = this.session.currentUser();
+ });
+ }
+
+ openLogin() {
+ this.modalInstance = this.$modal.open({
+ templateUrl: 'app/components/auth/login.html',
+ controller: AuthController,
+ controllerAs: 'vm',
+ bindToController: true
+ });
+ };
+
+ logout() {
+ this.authService.logout();
+ this.$state.go(this.$state.current, {}, { reload: true }); // TODO move to auth
+ };
+
+
+
+ activate() {
+ if (!this.currentUser) {
+ this.openLogin();
+ }
+ }
+
+}
diff --git a/src/app/login/auth-events.ts b/src/app/login/auth-events.ts
new file mode 100644
index 0000000..875d139
--- /dev/null
+++ b/src/app/login/auth-events.ts
@@ -0,0 +1,11 @@
+export interface IAuthEvents {
+ loginSuccess: string;
+ loginFailed: string;
+ logoutSuccess: string;
+}
+
+export const AUTH_EVENTS: IAuthEvents = {
+ loginSuccess: "auth-login-success",
+ loginFailed: "auth-login-failed",
+ logoutSuccess: "auth-logout-success"
+};
\ No newline at end of file
diff --git a/src/app/login/auth.controller.spec.ts b/src/app/login/auth.controller.spec.ts
new file mode 100644
index 0000000..b745f0e
--- /dev/null
+++ b/src/app/login/auth.controller.spec.ts
@@ -0,0 +1,33 @@
+import {AuthController} from "./auth.controller";
+import {AuthService} from "./auth.service";
+
+describe("Controllers", () => {
+
+
+ describe("AuthController", () => {
+
+ it("calls authenticate on AuthService when login called", () => {
+
+ // creating a Mock AuthService
+ let AuthServiceMock: AuthService = jasmine.createSpyObj("AuthService", ["login"]);
+
+ // pass AuthServiceMock into the constructor
+ let authController = new AuthController(null, null, AuthServiceMock);
+
+ // setup of authController -> set the credentials instance property
+ let credentials = { username: "username", password: "password" };
+
+ authController.credentials = credentials;
+
+ // calls the authController login method
+ authController.login();
+
+ // checks if the method login of the injected AuthService has been called
+ expect(AuthServiceMock.login).toHaveBeenCalledWith(credentials);
+
+ });
+
+
+
+ });
+});
diff --git a/src/app/login/auth.controller.ts b/src/app/login/auth.controller.ts
new file mode 100644
index 0000000..ff9664c
--- /dev/null
+++ b/src/app/login/auth.controller.ts
@@ -0,0 +1,20 @@
+import {AuthService} from "./auth.service";
+
+export class AuthController {
+
+ static $inject = ["$log", "$stateParams", "AuthService"];
+
+ constructor(
+ private $log: ng.ILogService,
+ private $stateParams: any,
+ private AuthService: AuthService
+ ) {
+
+ }
+
+ credentials: noosfero.Credentials;
+
+ login() {
+ this.AuthService.login(this.credentials);
+ }
+}
diff --git a/src/app/login/auth.service.spec.ts b/src/app/login/auth.service.spec.ts
new file mode 100644
index 0000000..5b417ba
--- /dev/null
+++ b/src/app/login/auth.service.spec.ts
@@ -0,0 +1,81 @@
+
+
+import {AuthService, AUTH_EVENTS} from "./";
+
+describe("Services", () => {
+
+
+ describe("Auth Service", () => {
+
+ let $httpBackend: ng.IHttpBackendService;
+ let authService: AuthService;
+ let credentials: noosfero.Credentials;
+ let $rootScope: ng.IRootScopeService;
+ let user: noosfero.User;
+
+ beforeEach(angular.mock.module("noosferoApp", ($translateProvider: angular.translate.ITranslateProvider) => {
+ $translateProvider.translations('en', {});
+ }));
+
+ beforeEach(inject((_$httpBackend_: ng.IHttpBackendService, _$rootScope_: ng.IRootScopeService, _AuthService_: AuthService) => {
+ $httpBackend = _$httpBackend_;
+ authService = _AuthService_;
+ $rootScope = _$rootScope_;
+
+ user = {
+ id: 1,
+ login: "user"
+ };
+ }));
+
+
+ describe("Succesffull login", () => {
+
+ beforeEach(() => {
+ credentials = { username: "user", password: "password" };
+
+ $httpBackend.expectPOST("/api/v1/login", "login=user&password=password").respond(200, { user: user });
+ });
+
+ it("should return loggedUser", (done) => {
+ authService.login(credentials).then((loggedUser) => {
+ expect(loggedUser).toBeDefined();
+ done();
+ });
+ $httpBackend.flush();
+ expect($httpBackend.verifyNoOutstandingRequest());
+ });
+
+
+ it("should emit event loggin successful with user logged data", () => {
+
+ authService.login(credentials);
+
+ let eventEmmited: boolean = false;
+ $rootScope.$on(AUTH_EVENTS.loginSuccess, (event: ng.IAngularEvent, userThroughEvent: noosfero.User) => {
+ eventEmmited = true;
+ expect(userThroughEvent).toEqual(user);
+ });
+
+ $httpBackend.flush();
+
+ expect(eventEmmited).toBeTruthy(AUTH_EVENTS.loginSuccess + " was not emmited!");
+ });
+
+ it("should return the current logged in user", () => {
+ authService.login(credentials);
+ $httpBackend.flush();
+ let actual: noosfero.User = authService.currentUser();
+ expect(actual).toEqual(user, "The returned user must be present");
+ });
+
+ it("should not return the current user after logout", () => {
+ authService.logout();
+ let actual: any = authService.currentUser();
+ expect(actual).toEqual(undefined, "The returned user must not be defined");
+ });
+ });
+
+
+ });
+});
diff --git a/src/app/login/auth.service.ts b/src/app/login/auth.service.ts
new file mode 100644
index 0000000..3c39e20
--- /dev/null
+++ b/src/app/login/auth.service.ts
@@ -0,0 +1,69 @@
+import {Injectable, Inject} from "ng-forward";
+
+import {NoosferoRootScope, UserResponse} from "./../shared/models/interfaces";
+import {SessionService} from "./session.service";
+
+import {AUTH_EVENTS, IAuthEvents} from "./auth-events";
+
+@Injectable()
+@Inject("$q", "$http", "$rootScope", "SessionService", "$log", "AUTH_EVENTS")
+export class AuthService {
+
+ constructor(private $q: ng.IQService,
+ private $http: ng.IHttpService,
+ private $rootScope: NoosferoRootScope,
+ private sessionService: SessionService,
+ private $log: ng.ILogService,
+ private auth_events: IAuthEvents) {
+
+ }
+
+ loginFromCookie() {
+ let url: string = '/api/v1/login_from_cookie';
+ return this.$http.post(url, null).then(this.loginSuccessCallback.bind(this), this.loginFailedCallback.bind(this));
+ }
+
+
+ private loginSuccessCallback(response: ng.IHttpPromiseCallbackArg) {
+ this.$log.debug('AuthService.login [SUCCESS] response', response);
+ let currentUser: noosfero.User = this.sessionService.create(response.data);
+ this.$rootScope.currentUser = currentUser;
+ this.$rootScope.$broadcast(this.auth_events.loginSuccess, currentUser);
+ return currentUser;
+ }
+
+ login(credentials: noosfero.Credentials): ng.IPromise {
+ let url = '/api/v1/login';
+ let encodedData = 'login=' + credentials.username + '&password=' + credentials.password;
+ return this.$http.post(url, encodedData).then(this.loginSuccessCallback.bind(this), this.loginFailedCallback.bind(this));
+ }
+
+ private loginFailedCallback(response: ng.IHttpPromiseCallbackArg): any {
+ this.$log.debug('AuthService.login [FAIL] response', response);
+ this.$rootScope.$broadcast(this.auth_events.loginFailed);
+ // return $q.reject(response);
+ return null;
+ }
+
+ public logout() {
+ this.sessionService.destroy();
+ this.$rootScope.currentUser = undefined;
+ this.$rootScope.$broadcast(this.auth_events.logoutSuccess);
+ this.$http.jsonp('/account/logout'); // FIXME logout from noosfero to sync login state
+ }
+
+ public isAuthenticated() {
+ return !!this.sessionService.currentUser();
+ }
+
+ public currentUser(): noosfero.User {
+ return this.sessionService.currentUser();
+ }
+
+ public isAuthorized(authorizedRoles: string | string[]) {
+ if (!angular.isArray(authorizedRoles)) {
+ authorizedRoles = [authorizedRoles];
+ }
+ return (this.isAuthenticated() && authorizedRoles.indexOf(this.sessionService.currentUser().userRole) !== -1);
+ }
+}
\ No newline at end of file
diff --git a/src/app/login/index.ts b/src/app/login/index.ts
new file mode 100644
index 0000000..2e4c25e
--- /dev/null
+++ b/src/app/login/index.ts
@@ -0,0 +1,5 @@
+/* Module Index Entry - generated using the script npm run generate-index */
+export * from "./auth-events";
+export * from "./auth.controller";
+export * from "./auth.service";
+export * from "./session.service";
diff --git a/src/app/login/login.html b/src/app/login/login.html
new file mode 100644
index 0000000..8c01ca8
--- /dev/null
+++ b/src/app/login/login.html
@@ -0,0 +1,16 @@
+
+
diff --git a/src/app/login/session.service.spec.ts b/src/app/login/session.service.spec.ts
new file mode 100644
index 0000000..4065435
--- /dev/null
+++ b/src/app/login/session.service.spec.ts
@@ -0,0 +1,49 @@
+import {Component} from "ng-forward";
+import {SessionService} from "./session.service";
+import {fixtures, createComponentFromClass, createProviderToValue} from "./../../spec/helpers";
+import {UserResponse, INoosferoLocalStorage} from "./../shared/models/interfaces";
+
+
+describe("Services", () => {
+
+
+ describe("Session Service", () => {
+
+ let $localStorage: INoosferoLocalStorage = null;
+ let $log: any;
+
+ beforeEach(() => {
+ $localStorage = { currentUser: null };
+ $log = jasmine.createSpyObj('$log', ['debug']);
+ });
+
+ it("method 'create()' saves the current user on $localstorage service", () => {
+ let session = new SessionService($localStorage, $log);
+ let userResponse = {
+ user: fixtures.user
+ };
+ session.create(userResponse);
+ expect($localStorage.currentUser).toEqual(userResponse.user);
+ });
+
+ it("method 'destroy()' clean the currentUser on $localstorage", () => {
+ let session = new SessionService($localStorage, $log);
+ let userResponse = {
+ user: fixtures.user
+ };
+ $localStorage.currentUser = fixtures.user;
+ session.destroy();
+ expect($localStorage.currentUser).toBeUndefined();
+ });
+
+ it("method 'currentUser()' returns the user recorded on $localstorage service", () => {
+ let session = new SessionService($localStorage, $log);
+ let userResponse = {
+ user: fixtures.user
+ };
+ $localStorage.currentUser = fixtures.user;
+ expect(session.currentUser()).toEqual($localStorage.currentUser);
+ });
+ });
+
+});
\ No newline at end of file
diff --git a/src/app/login/session.service.ts b/src/app/login/session.service.ts
new file mode 100644
index 0000000..8ac0b8b
--- /dev/null
+++ b/src/app/login/session.service.ts
@@ -0,0 +1,27 @@
+import {Injectable, Inject} from "ng-forward";
+import {UserResponse, INoosferoLocalStorage} from "./../shared/models/interfaces";
+
+@Injectable()
+@Inject("$localStorage", "$log")
+export class SessionService {
+
+ constructor(private $localStorage: INoosferoLocalStorage, private $log: ng.ILogService) {
+
+ }
+
+ create(data: UserResponse): noosfero.User {
+ this.$localStorage.currentUser = data.user;
+ this.$log.debug('User session created.', this.$localStorage.currentUser);
+ return this.$localStorage.currentUser;
+ };
+
+ destroy() {
+ delete this.$localStorage.currentUser;
+ this.$log.debug('User session destroyed.');
+ };
+
+ currentUser(): noosfero.User {
+ return this.$localStorage.currentUser;
+ };
+
+}
\ No newline at end of file
diff --git a/src/app/main/main.component.ts b/src/app/main/main.component.ts
index d54396b..b1e802e 100644
--- a/src/app/main/main.component.ts
+++ b/src/app/main/main.component.ts
@@ -1,28 +1,29 @@
import {bundle, Component, StateConfig} from "ng-forward";
-import {ArticleBlog} from "./../components/noosfero-articles/blog/blog.component";
+import {ArticleBlogComponent} from "./../article/types/blog/blog.component";
-import {ArticleView} from "../components/noosfero-articles/article/article_view";
+import {ArticleViewComponent} from "./../article/article-default-view.component";
-import {Profile} from "../profile/profile.component";
-import {Boxes} from "../components/noosfero-boxes/boxes.component";
-import {Block} from "../components/noosfero-blocks/block.component";
-import {LinkListBlock} from "../components/noosfero-blocks/link-list/link-list.component";
-import {RecentDocumentsBlock} from "../components/noosfero-blocks/recent-documents/recent-documents.component";
-import {ProfileImageBlock} from "../components/noosfero-blocks/profile-image-block/profile-image-block.component";
-import {RawHTMLBlock} from "../components/noosfero-blocks/raw-html/raw-html.component";
+import {ProfileComponent} from "../profile/profile.component";
+import {BoxesComponent} from "../layout/boxes/boxes.component";
+import {BlockComponent} from "../layout/blocks/block.component";
+import {LinkListBlockComponent} from "./../layout/blocks/link-list/link-list.component";
+import {RecentDocumentsBlockComponent} from "../layout/blocks/recent-documents/recent-documents.component";
+import {ProfileImageBlockComponent} from "../layout/blocks/profile-image-block/profile-image-block.component";
+import {RawHTMLBlockComponent} from "../layout/blocks/raw-html/raw-html.component";
-import {MembersBlock} from "../components/noosfero-blocks/members-block/members-block.component";
-import {NoosferoTemplate} from "../components/noosfero/noosfero-template.filter";
-import {DateFormat} from "../components/noosfero/date-format/date-format.filter";
+import {MembersBlockComponent} from "./../layout/blocks/members-block/members-block.component";
+import {NoosferoTemplate} from "../shared/pipes/noosfero-template.filter";
+import {DateFormat} from "../shared/pipes/date-format.filter";
-import {AuthService} from "./../components/auth/auth_service";
-import {Session} from "./../components/auth/session";
-import {Notification} from "./../components/notification/notification.component";
+import {AuthService} from "../login/auth.service";
+import {SessionService} from "../login/session.service";
+import {NotificationService} from "../shared/services/notification.service";
-import {Navbar} from "../components/navbar/navbar";
-import {MainBlock} from "../components/noosfero-blocks/main-block/main-block.component";
+import {Navbar} from "../layout/navbar/navbar";
+
+import {MainBlockComponent} from "../layout/blocks/main-block/main-block.component";
/**
@@ -38,7 +39,7 @@ import {MainBlock} from "../components/noosfero-blocks/main-block/main-block.com
@Component({
selector: 'main-content',
templateUrl: "app/main/main.html",
- providers: [AuthService, Session]
+ providers: [AuthService, SessionService]
})
export class MainContent {
@@ -62,11 +63,11 @@ export class MainContent {
selector: 'main',
template: '
',
directives: [
- ArticleBlog, ArticleView, Boxes, Block, LinkListBlock,
- MainBlock, RecentDocumentsBlock, Navbar, ProfileImageBlock,
- MembersBlock, NoosferoTemplate, DateFormat, RawHTMLBlock
+ ArticleBlogComponent, ArticleViewComponent, BoxesComponent, BlockComponent, LinkListBlockComponent,
+ MainBlockComponent, RecentDocumentsBlockComponent, Navbar, ProfileImageBlockComponent,
+ MembersBlockComponent, NoosferoTemplate, DateFormat, RawHTMLBlockComponent
],
- providers: [AuthService, Session, Notification]
+ providers: [AuthService, SessionService, NotificationService]
})
@StateConfig([
{
@@ -77,12 +78,12 @@ export class MainContent {
{
url: "^/:profile",
abstract: true,
- component: Profile,
+ component: ProfileComponent,
name: 'main.profile',
views: {
"content": {
templateUrl: "app/profile/profile.html",
- controller: Profile,
+ controller: ProfileComponent,
controllerAs: "vm"
}
}
diff --git a/src/app/models/index.ts b/src/app/models/index.ts
deleted file mode 100644
index 181d29e..0000000
--- a/src/app/models/index.ts
+++ /dev/null
@@ -1,2 +0,0 @@
-/* Module Index Entry - generated using the script npm run generate-index */
-export * from "./interfaces";
diff --git a/src/app/models/interfaces.ts b/src/app/models/interfaces.ts
deleted file mode 100644
index 3b384f8..0000000
--- a/src/app/models/interfaces.ts
+++ /dev/null
@@ -1,12 +0,0 @@
-export interface NoosferoRootScope extends ng.IScope {
- currentUser: noosfero.User;
-}
-
-export interface UserResponse {
- user: noosfero.User;
-}
-
-
-export interface INoosferoLocalStorage extends angular.storage.ILocalStorageService {
- currentUser: noosfero.User;
-}
diff --git a/src/app/profile-info/index.ts b/src/app/profile-info/index.ts
deleted file mode 100644
index 00329c7..0000000
--- a/src/app/profile-info/index.ts
+++ /dev/null
@@ -1,2 +0,0 @@
-/* Module Index Entry - generated using the script npm run generate-index */
-export * from "./profile-info.component";
diff --git a/src/app/profile-info/profile-info.component.spec.ts b/src/app/profile-info/profile-info.component.spec.ts
deleted file mode 100644
index 5b51644..0000000
--- a/src/app/profile-info/profile-info.component.spec.ts
+++ /dev/null
@@ -1,40 +0,0 @@
-import {quickCreateComponent} from "../../spec/helpers";
-import {ProfileInfo} from "./profile-info.component";
-
-describe("Components", () => {
- describe("Profile Info Component", () => {
-
- let $rootScope: ng.IRootScopeService;
- let $q: ng.IQService;
- let profileServiceMock: any;
- let $stateParams: any;
-
- beforeEach(inject((_$rootScope_: ng.IRootScopeService, _$q_: ng.IQService) => {
- $rootScope = _$rootScope_;
- $q = _$q_;
- }));
-
- beforeEach(() => {
- $stateParams = jasmine.createSpyObj("$stateParams", ["profile"]);
- profileServiceMock = jasmine.createSpyObj("profileServiceMock", ["getCurrentProfile", "getActivities"]);
-
- let getCurrentProfileResponse = $q.defer();
- getCurrentProfileResponse.resolve({ id: 1 });
-
- let getActivitiesResponse = $q.defer();
- getActivitiesResponse.resolve({ data: { activities: [{ id: 1 }, { id: 2 }] } });
-
- profileServiceMock.getCurrentProfile = jasmine.createSpy("getCurrentProfile").and.returnValue(getCurrentProfileResponse.promise);
- profileServiceMock.getActivities = jasmine.createSpy("getActivities").and.returnValue(getActivitiesResponse.promise);
- });
-
- it("get the profile activities", done => {
- let component: ProfileInfo = new ProfileInfo(profileServiceMock);
- $rootScope.$apply();
- expect(profileServiceMock.getCurrentProfile).toHaveBeenCalled();
- expect(profileServiceMock.getActivities).toHaveBeenCalled();
- expect(component.activities).toEqual([{ id: 1 }, { id: 2 }]);
- done();
- });
- });
-});
diff --git a/src/app/profile-info/profile-info.component.ts b/src/app/profile-info/profile-info.component.ts
deleted file mode 100644
index e18371e..0000000
--- a/src/app/profile-info/profile-info.component.ts
+++ /dev/null
@@ -1,27 +0,0 @@
-import {StateConfig, Component, Inject, provide} from 'ng-forward';
-import {ProfileService} from "../../lib/ng-noosfero-api/http/profile.service";
-
-@Component({
- selector: 'profile',
- templateUrl: "app/profile-info/profile-info.html",
- providers: [provide('profileService', { useClass: ProfileService })]
-})
-@Inject(ProfileService)
-export class ProfileInfo {
-
- activities: any;
- profile: noosfero.Profile;
-
- constructor(private profileService: ProfileService) {
- this.activate();
- }
-
- activate() {
- this.profileService.getCurrentProfile().then((profile: noosfero.Profile) => {
- this.profile = profile;
- return this.profileService.getActivities(this.profile.id);
- }).then((response: restangular.IResponse) => {
- this.activities = response.data.activities;
- });
- }
-}
diff --git a/src/app/profile-info/profile-info.html b/src/app/profile-info/profile-info.html
deleted file mode 100644
index c98d4d2..0000000
--- a/src/app/profile-info/profile-info.html
+++ /dev/null
@@ -1,6 +0,0 @@
-{{vm.profile.name}}
-
-
-
{{"profile.wall" | translate}}
-
-
diff --git a/src/app/profile/activities/activities.component.spec.ts b/src/app/profile/activities/activities.component.spec.ts
new file mode 100644
index 0000000..e180bf2
--- /dev/null
+++ b/src/app/profile/activities/activities.component.spec.ts
@@ -0,0 +1,36 @@
+import {TestComponentBuilder} from 'ng-forward/cjs/testing/test-component-builder';
+import {Pipe, Input, provide, Component} from 'ng-forward';
+import {provideFilters} from '../../../spec/helpers';
+
+import {ActivitiesComponent} from './activities.component';
+
+const tcb = new TestComponentBuilder();
+
+const htmlTemplate: string = ' ';
+
+
+describe("Components", () => {
+
+ describe("Noosfero Activities", () => {
+
+ beforeEach(angular.mock.module("templates"));
+
+ @Component({
+ selector: 'test-container-component',
+ template: htmlTemplate,
+ directives: [ActivitiesComponent],
+ providers: provideFilters("truncateFilter", "stripTagsFilter", "translateFilter")
+ })
+ class BlockContainerComponent {
+ activities = [{ name: "activity1", verb: "create_article" }, { name: "activity2", verb: "create_article" }];
+ }
+
+ it("render a noosfero activity tag for each activity", done => {
+ tcb.createAsync(BlockContainerComponent).then(fixture => {
+ expect(fixture.debugElement.queryAll("noosfero-activity").length).toEqual(2);
+ done();
+ });
+ });
+ });
+
+});
diff --git a/src/app/profile/activities/activities.component.ts b/src/app/profile/activities/activities.component.ts
new file mode 100644
index 0000000..1a43656
--- /dev/null
+++ b/src/app/profile/activities/activities.component.ts
@@ -0,0 +1,27 @@
+import {Component, Input} from "ng-forward";
+import {ActivityComponent} from "./activity/activity.component";
+
+/**
+ * @ngdoc controller
+ * @name NoosferoActivities
+ * @description
+ * The controller responsible to retreive profile activities.
+ */
+
+@Component({
+ selector: "noosfero-activities",
+ templateUrl: 'app/profile/activities/activities.html',
+ directives: [ActivityComponent]
+})
+export class ActivitiesComponent {
+
+ /**
+ * @ngdoc property
+ * @propertyOf NoosferoActivities
+ * @name activities
+ * @returns {Activity[]} An array of {@link Activity}.
+ */
+ @Input() activities: noosfero.Activity[];
+
+
+}
diff --git a/src/app/profile/activities/activities.html b/src/app/profile/activities/activities.html
new file mode 100644
index 0000000..f99e3e3
--- /dev/null
+++ b/src/app/profile/activities/activities.html
@@ -0,0 +1,5 @@
+
+
+
+
+
diff --git a/src/app/profile/activities/activities.scss b/src/app/profile/activities/activities.scss
new file mode 100644
index 0000000..88982c9
--- /dev/null
+++ b/src/app/profile/activities/activities.scss
@@ -0,0 +1,11 @@
+.comma-separated {
+ .separated-item {
+ &:after {
+ content: ", ";
+ margin-left: -3px;
+ }
+ &:last-child:after {
+ content: "";
+ }
+ }
+}
diff --git a/src/app/profile/activities/activity/activity.component.spec.ts b/src/app/profile/activities/activity/activity.component.spec.ts
new file mode 100644
index 0000000..ed6f98c
--- /dev/null
+++ b/src/app/profile/activities/activity/activity.component.spec.ts
@@ -0,0 +1,38 @@
+import {TestComponentBuilder} from 'ng-forward/cjs/testing/test-component-builder';
+import {Pipe, Input, provide, Component} from 'ng-forward';
+import {provideFilters} from '../../../../spec/helpers';
+
+import {ActivityComponent} from './activity.component';
+
+const tcb = new TestComponentBuilder();
+
+const htmlTemplate: string = ' ';
+
+
+describe("Components", () => {
+
+ describe("Noosfero Activity", () => {
+
+ beforeEach(angular.mock.module("templates"));
+
+ @Component({
+ selector: 'test-container-component',
+ template: htmlTemplate,
+ directives: [ActivityComponent],
+ providers: provideFilters("truncateFilter", "stripTagsFilter", "translateFilter")
+ })
+ class BlockContainerComponent {
+ activity = { name: "activity1", verb: "create_article" };
+ }
+
+ it("render the specific template for an activity verb", done => {
+ tcb.createAsync(BlockContainerComponent).then(fixture => {
+ let component: ActivityComponent = fixture.debugElement.componentViewChildren[0].componentInstance;
+ expect(component.getActivityTemplate()).toEqual('app/profile/activities/activity/create_article.html');
+ expect(fixture.debugElement.queryAll(".activity.create_article").length).toEqual(1);
+ done();
+ });
+ });
+ });
+
+});
diff --git a/src/app/profile/activities/activity/activity.component.ts b/src/app/profile/activities/activity/activity.component.ts
new file mode 100644
index 0000000..6ec700e
--- /dev/null
+++ b/src/app/profile/activities/activity/activity.component.ts
@@ -0,0 +1,15 @@
+import {Component, Input} from "ng-forward";
+
+@Component({
+ selector: "noosfero-activity",
+ templateUrl: 'app/profile/activities/activity/activity.html'
+})
+export class ActivityComponent {
+
+ @Input() activity: noosfero.Activity;
+
+ getActivityTemplate() {
+ return 'app/profile/activities/activity/' + this.activity.verb + '.html';
+ }
+
+}
diff --git a/src/app/profile/activities/activity/activity.html b/src/app/profile/activities/activity/activity.html
new file mode 100644
index 0000000..0bcc9b7
--- /dev/null
+++ b/src/app/profile/activities/activity/activity.html
@@ -0,0 +1,3 @@
+
+
+
diff --git a/src/app/profile/activities/activity/add_member_in_community.html b/src/app/profile/activities/activity/add_member_in_community.html
new file mode 100644
index 0000000..b97512f
--- /dev/null
+++ b/src/app/profile/activities/activity/add_member_in_community.html
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+ {{"activities.add_member_in_community.description" | translate}}
+
+
+
+
+
diff --git a/src/app/profile/activities/activity/create_article.html b/src/app/profile/activities/activity/create_article.html
new file mode 100644
index 0000000..791ef13
--- /dev/null
+++ b/src/app/profile/activities/activity/create_article.html
@@ -0,0 +1,26 @@
+
+
+
+
+
+
+
+ {{"activities.create_article.description" | translate}}
+
+
+
+
+
+
+
+
diff --git a/src/app/profile/activities/activity/index.ts b/src/app/profile/activities/activity/index.ts
new file mode 100644
index 0000000..4342b8e
--- /dev/null
+++ b/src/app/profile/activities/activity/index.ts
@@ -0,0 +1,2 @@
+/* Module Index Entry - generated using the script npm run generate-index */
+export * from "./activity.component";
diff --git a/src/app/profile/activities/activity/new_friendship.html b/src/app/profile/activities/activity/new_friendship.html
new file mode 100644
index 0000000..c19d66d
--- /dev/null
+++ b/src/app/profile/activities/activity/new_friendship.html
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+ {{"activities.new_friendship.description" | translate:{friends: ctrl.activity.params.friend_name.length}:"messageformat" }}
+
+
+
+
+
+
+
+
+
+
diff --git a/src/app/profile/activities/index.ts b/src/app/profile/activities/index.ts
new file mode 100644
index 0000000..38d8dce
--- /dev/null
+++ b/src/app/profile/activities/index.ts
@@ -0,0 +1,2 @@
+/* Module Index Entry - generated using the script npm run generate-index */
+export * from "./activities.component";
diff --git a/src/app/profile/image/image.component.spec.ts b/src/app/profile/image/image.component.spec.ts
new file mode 100644
index 0000000..13e02ff
--- /dev/null
+++ b/src/app/profile/image/image.component.spec.ts
@@ -0,0 +1,51 @@
+/**
+ * @ngdoc overview
+ * @name components.noosfero.profile-image.ProfileImageSpec
+ * @description
+ * This file contains the tests for the {@link components.noosfero.profile-image.ProfileImage} component.
+ */
+
+import {TestComponentBuilder, ComponentFixture} from 'ng-forward/cjs/testing/test-component-builder';
+import {Pipe, Input, provide, Component} from 'ng-forward';
+
+import * as helpers from "../../../spec/helpers";
+
+import {ProfileImageComponent} from "./image.component";
+
+const tcb = new TestComponentBuilder();
+
+describe("Components", () => {
+
+ describe("Profile Image Component", () => {
+
+ beforeEach(angular.mock.module("templates"));
+
+ it("show community users image if profile is not Person", done => {
+ helpers.tcb.createAsync(ProfileImageComponent).then(fixture => {
+ let profileImageComponent: ProfileImageComponent = fixture.componentInstance;
+ let profile = { id: 1, identifier: "myprofile", type: "Community" };
+ profileImageComponent.profile = profile;
+ profileImageComponent.ngOnInit();
+
+ // Check the attribute
+ expect(profileImageComponent.defaultIcon).toBe("fa-users", "The default icon should be community users");
+ // var elProfile = fixture.debugElement.componentViewChildren[0];
+ // expect(elProfile.query('div.profile-image-block').length).toEqual(1);
+ done();
+ });
+ });
+
+ it("show Person image if profile is Person", done => {
+ tcb.createAsync(ProfileImageComponent).then(fixture => {
+ let profileImageComponent: ProfileImageComponent = fixture.componentInstance;
+ let profile = { id: 1, identifier: "myprofile", type: "Person" };
+ profileImageComponent.profile = profile;
+ profileImageComponent.ngOnInit();
+ // Check the attribute
+ expect(profileImageComponent.defaultIcon).toEqual("fa-user", "The default icon should be person user");
+ done();
+ });
+ });
+
+ });
+});
\ No newline at end of file
diff --git a/src/app/profile/image/image.component.ts b/src/app/profile/image/image.component.ts
new file mode 100644
index 0000000..a35ae94
--- /dev/null
+++ b/src/app/profile/image/image.component.ts
@@ -0,0 +1,47 @@
+import {Inject, Input, Component} from "ng-forward";
+
+
+/**
+ * @ngdoc controller
+ * @name components.noosfero.profile-image.ProfileImage
+ * @description The component responsible for rendering the profile image
+ * @exports ProfileImage
+ */
+@Component({
+ selector: "noosfero-profile-image",
+ templateUrl: 'app/profile/image/image.html',
+})
+export class ProfileImageComponent {
+
+ /**
+ * @ngdoc property
+ * @name profile
+ * @propertyOf components.noosfero.profile-image.ProfileImage
+ * @description
+ * The Noosfero {@link models.Profile} holding the image.
+ */
+ @Input() profile: noosfero.Profile;
+ /**
+ * @ngdoc property
+ * @name defaultIcon
+ * @propertyOf components.noosfero.profile-image.ProfileImage
+ * @descritpion
+ * The default icon used by this profile
+ */
+ defaultIcon: string;
+
+ /**
+ * @ngdoc method
+ * @name ngOnInit
+ * @methodOf components.noosfero.profile-image.ProfileImage
+ * @description
+ * Initializes the icon names to their corresponding values depending on the profile type passed to the controller
+ */
+ ngOnInit() {
+ this.defaultIcon = 'fa-users';
+ if (this.profile && this.profile.type === 'Person') {
+ this.defaultIcon = 'fa-user';
+ }
+ }
+}
+
diff --git a/src/app/profile/image/image.html b/src/app/profile/image/image.html
new file mode 100644
index 0000000..b1418b6
--- /dev/null
+++ b/src/app/profile/image/image.html
@@ -0,0 +1,4 @@
+
+
+
+
diff --git a/src/app/profile/image/image.scss b/src/app/profile/image/image.scss
new file mode 100644
index 0000000..f2f8fb8
--- /dev/null
+++ b/src/app/profile/image/image.scss
@@ -0,0 +1,3 @@
+i.profile-image {
+ color: rgb(44, 62, 80);
+}
diff --git a/src/app/profile/image/index.ts b/src/app/profile/image/index.ts
new file mode 100644
index 0000000..65995e1
--- /dev/null
+++ b/src/app/profile/image/index.ts
@@ -0,0 +1,2 @@
+/* Module Index Entry - generated using the script npm run generate-index */
+export * from "./image.component";
diff --git a/src/app/profile/index.ts b/src/app/profile/index.ts
index c3247f5..eb0d906 100644
--- a/src/app/profile/index.ts
+++ b/src/app/profile/index.ts
@@ -1,3 +1,4 @@
/* Module Index Entry - generated using the script npm run generate-index */
+export * from "./myprofile.component";
export * from "./profile-home.component";
export * from "./profile.component";
diff --git a/src/app/profile/info/index.ts b/src/app/profile/info/index.ts
new file mode 100644
index 0000000..00329c7
--- /dev/null
+++ b/src/app/profile/info/index.ts
@@ -0,0 +1,2 @@
+/* Module Index Entry - generated using the script npm run generate-index */
+export * from "./profile-info.component";
diff --git a/src/app/profile/info/profile-info.component.spec.ts b/src/app/profile/info/profile-info.component.spec.ts
new file mode 100644
index 0000000..d22c405
--- /dev/null
+++ b/src/app/profile/info/profile-info.component.spec.ts
@@ -0,0 +1,40 @@
+import {quickCreateComponent} from "../../../spec/helpers";
+import {ProfileInfoComponent} from "./profile-info.component";
+
+describe("Components", () => {
+ describe("Profile Info Component", () => {
+
+ let $rootScope: ng.IRootScopeService;
+ let $q: ng.IQService;
+ let profileServiceMock: any;
+ let $stateParams: any;
+
+ beforeEach(inject((_$rootScope_: ng.IRootScopeService, _$q_: ng.IQService) => {
+ $rootScope = _$rootScope_;
+ $q = _$q_;
+ }));
+
+ beforeEach(() => {
+ $stateParams = jasmine.createSpyObj("$stateParams", ["profile"]);
+ profileServiceMock = jasmine.createSpyObj("profileServiceMock", ["getCurrentProfile", "getActivities"]);
+
+ let getCurrentProfileResponse = $q.defer();
+ getCurrentProfileResponse.resolve({ id: 1 });
+
+ let getActivitiesResponse = $q.defer();
+ getActivitiesResponse.resolve({ data: { activities: [{ id: 1 }, { id: 2 }] } });
+
+ profileServiceMock.getCurrentProfile = jasmine.createSpy("getCurrentProfile").and.returnValue(getCurrentProfileResponse.promise);
+ profileServiceMock.getActivities = jasmine.createSpy("getActivities").and.returnValue(getActivitiesResponse.promise);
+ });
+
+ it("get the profile activities", done => {
+ let component: ProfileInfoComponent = new ProfileInfoComponent(profileServiceMock);
+ $rootScope.$apply();
+ expect(profileServiceMock.getCurrentProfile).toHaveBeenCalled();
+ expect(profileServiceMock.getActivities).toHaveBeenCalled();
+ expect(component.activities).toEqual([{ id: 1 }, { id: 2 }]);
+ done();
+ });
+ });
+});
diff --git a/src/app/profile/info/profile-info.component.ts b/src/app/profile/info/profile-info.component.ts
new file mode 100644
index 0000000..0055aea
--- /dev/null
+++ b/src/app/profile/info/profile-info.component.ts
@@ -0,0 +1,27 @@
+import {StateConfig, Component, Inject, provide} from 'ng-forward';
+import {ProfileService} from "../../../lib/ng-noosfero-api/http/profile.service";
+
+@Component({
+ selector: 'profile',
+ templateUrl: "app/profile-info/profile-info.html",
+ providers: [provide('profileService', { useClass: ProfileService })]
+})
+@Inject(ProfileService)
+export class ProfileInfoComponent {
+
+ activities: any;
+ profile: noosfero.Profile;
+
+ constructor(private profileService: ProfileService) {
+ this.activate();
+ }
+
+ activate() {
+ this.profileService.getCurrentProfile().then((profile: noosfero.Profile) => {
+ this.profile = profile;
+ return this.profileService.getActivities(this.profile.id);
+ }).then((response: restangular.IResponse) => {
+ this.activities = response.data.activities;
+ });
+ }
+}
diff --git a/src/app/profile/info/profile-info.html b/src/app/profile/info/profile-info.html
new file mode 100644
index 0000000..c98d4d2
--- /dev/null
+++ b/src/app/profile/info/profile-info.html
@@ -0,0 +1,6 @@
+{{vm.profile.name}}
+
+
+
{{"profile.wall" | translate}}
+
+
diff --git a/src/app/profile/profile.component.spec.ts b/src/app/profile/profile.component.spec.ts
index 70f35f8..0af4c18 100644
--- a/src/app/profile/profile.component.spec.ts
+++ b/src/app/profile/profile.component.spec.ts
@@ -1,5 +1,5 @@
import {quickCreateComponent} from "../../spec/helpers";
-import {Profile} from "./profile.component";
+import {ProfileComponent} from "./profile.component";
describe("Components", () => {
describe("Profile Component", () => {
@@ -30,7 +30,7 @@ describe("Components", () => {
});
it("get the profile and store in profile service", done => {
- let component: Profile = new Profile(profileServiceMock, $stateParams, notificationMock);
+ let component: ProfileComponent = new ProfileComponent(profileServiceMock, $stateParams, notificationMock);
$rootScope.$apply();
expect(profileServiceMock.setCurrentProfileByIdentifier).toHaveBeenCalled();
expect(component.profile).toEqual({ id: 1 });
@@ -38,7 +38,7 @@ describe("Components", () => {
});
it("get the profile boxes", done => {
- let component: Profile = new Profile(profileServiceMock, $stateParams, notificationMock);
+ let component: ProfileComponent = new ProfileComponent(profileServiceMock, $stateParams, notificationMock);
$rootScope.$apply();
expect(profileServiceMock.getBoxes).toHaveBeenCalled();
expect(component.boxes).toEqual([{ id: 2 }]);
@@ -50,7 +50,7 @@ describe("Components", () => {
profileResponse.reject();
profileServiceMock.setCurrentProfileByIdentifier = jasmine.createSpy("setCurrentProfileByIdentifier").and.returnValue(profileResponse.promise);
- let component: Profile = new Profile(profileServiceMock, $stateParams, notificationMock);
+ let component: ProfileComponent = new ProfileComponent(profileServiceMock, $stateParams, notificationMock);
$rootScope.$apply();
expect(profileServiceMock.setCurrentProfileByIdentifier).toHaveBeenCalled();
diff --git a/src/app/profile/profile.component.ts b/src/app/profile/profile.component.ts
index ad1daa1..0f09724 100644
--- a/src/app/profile/profile.component.ts
+++ b/src/app/profile/profile.component.ts
@@ -1,12 +1,12 @@
import {StateConfig, Component, Inject, provide} from 'ng-forward';
-import {ProfileInfo} from '../profile-info/profile-info.component';
-import {ProfileHome} from '../profile/profile-home.component';
-import {Cms} from '../cms/cms.component';
-import {ContentViewer} from "../content-viewer/content-viewer.component";
-import {ContentViewerActions} from "../content-viewer/content-viewer-actions.component";
-import {NoosferoActivities} from "../components/noosfero-activities/activities.component";
+import {ProfileInfoComponent} from './info/profile-info.component';
+import {ProfileHome} from './profile-home.component';
+import {BasicEditorComponent} from '../article/basic-editor.component';
+import {ContentViewerComponent} from "../article/content-viewer/content-viewer.component";
+import {ContentViewerActions} from "../article/content-viewer/content-viewer-actions.component";
+import {ActivitiesComponent} from "./activities/activities.component";
import {ProfileService} from "../../lib/ng-noosfero-api/http/profile.service";
-import {Notification} from "../components/notification/notification.component";
+import {NotificationService} from "../shared/services/notification.service";
import {MyProfile} from "./myprofile.component";
@@ -20,21 +20,21 @@ import {MyProfile} from "./myprofile.component";
@Component({
selector: 'profile',
templateUrl: "app/profile/profile.html",
- directives: [NoosferoActivities],
+ directives: [ActivitiesComponent],
providers: [
provide('profileService', { useClass: ProfileService }),
- provide('notification', { useClass: Notification })
+ provide('notificationService', { useClass: NotificationService })
]
})
@StateConfig([
{
name: 'main.profile.info',
url: "^/profile/:profile",
- component: ProfileInfo,
+ component: ProfileInfoComponent,
views: {
"mainBlockContent": {
templateUrl: "app/profile-info/profile-info.html",
- controller: ProfileInfo,
+ controller: ProfileInfoComponent,
controllerAs: "vm"
}
}
@@ -47,11 +47,11 @@ import {MyProfile} from "./myprofile.component";
{
name: 'main.profile.cms',
url: "^/myprofile/:profile/cms",
- component: Cms,
+ component: BasicEditorComponent,
views: {
"mainBlockContent": {
- templateUrl: "app/cms/cms.html",
- controller: Cms,
+ templateUrl: "app/article/basic-editor.html",
+ controller: BasicEditorComponent,
controllerAs: "vm"
}
}
@@ -70,11 +70,11 @@ import {MyProfile} from "./myprofile.component";
{
name: 'main.profile.page',
url: "/{page:any}",
- component: ContentViewer,
+ component: ContentViewerComponent,
views: {
"mainBlockContent": {
templateUrl: "app/content-viewer/page.html",
- controller: ContentViewer,
+ controller: ContentViewerComponent,
controllerAs: "vm"
},
"actions@main": {
@@ -86,19 +86,19 @@ import {MyProfile} from "./myprofile.component";
}
])
@Inject(ProfileService, "$stateParams")
-export class Profile {
+export class ProfileComponent {
boxes: noosfero.Box[];
profile: noosfero.Profile;
- constructor(profileService: ProfileService, $stateParams: ng.ui.IStateParamsService, notification: Notification) {
+ constructor(profileService: ProfileService, $stateParams: ng.ui.IStateParamsService, notificationService: NotificationService) {
profileService.setCurrentProfileByIdentifier($stateParams["profile"]).then((profile: noosfero.Profile) => {
this.profile = profile;
return profileService.getBoxes(this.profile.id);
}).then((response: restangular.IResponse) => {
this.boxes = response.data.boxes;
}).catch(() => {
- notification.error("notification.profile.not_found");
+ notificationService.error("notification.profile.not_found");
});
}
}
diff --git a/src/app/profile/profile.scss b/src/app/profile/profile.scss
index ab49f99..746c83f 100644
--- a/src/app/profile/profile.scss
+++ b/src/app/profile/profile.scss
@@ -1,6 +1,6 @@
.profile-container {
@extend .container-fluid;
- padding: 0 12%;
+ padding: 0 1%;
@media (max-width: 978px) {
padding: 0 2%;
}
diff --git a/src/app/registration/index.ts b/src/app/registration/index.ts
new file mode 100644
index 0000000..4206e70
--- /dev/null
+++ b/src/app/registration/index.ts
@@ -0,0 +1 @@
+/* Module Index Entry - generated using the script npm run generate-index */
diff --git a/src/app/shared/components/index.ts b/src/app/shared/components/index.ts
new file mode 100644
index 0000000..4206e70
--- /dev/null
+++ b/src/app/shared/components/index.ts
@@ -0,0 +1 @@
+/* Module Index Entry - generated using the script npm run generate-index */
diff --git a/src/app/shared/index.ts b/src/app/shared/index.ts
new file mode 100644
index 0000000..4206e70
--- /dev/null
+++ b/src/app/shared/index.ts
@@ -0,0 +1 @@
+/* Module Index Entry - generated using the script npm run generate-index */
diff --git a/src/app/shared/models/index.ts b/src/app/shared/models/index.ts
new file mode 100644
index 0000000..181d29e
--- /dev/null
+++ b/src/app/shared/models/index.ts
@@ -0,0 +1,2 @@
+/* Module Index Entry - generated using the script npm run generate-index */
+export * from "./interfaces";
diff --git a/src/app/shared/models/interfaces.ts b/src/app/shared/models/interfaces.ts
new file mode 100644
index 0000000..3b384f8
--- /dev/null
+++ b/src/app/shared/models/interfaces.ts
@@ -0,0 +1,12 @@
+export interface NoosferoRootScope extends ng.IScope {
+ currentUser: noosfero.User;
+}
+
+export interface UserResponse {
+ user: noosfero.User;
+}
+
+
+export interface INoosferoLocalStorage extends angular.storage.ILocalStorageService {
+ currentUser: noosfero.User;
+}
diff --git a/src/app/shared/pipes/date-format.filter.spec.ts b/src/app/shared/pipes/date-format.filter.spec.ts
new file mode 100644
index 0000000..2399ae5
--- /dev/null
+++ b/src/app/shared/pipes/date-format.filter.spec.ts
@@ -0,0 +1,20 @@
+import {quickCreateComponent} from "../../../spec/helpers";
+import {DateFormat} from './date-format.filter';
+
+describe("Filters", () => {
+ describe("Date Format Filter", () => {
+
+ beforeEach(angular.mock.module("templates"));
+ beforeEach(angular.mock.module("angularMoment"));
+
+ it("convert date from the format returned by noosfero api to an ISO format", done => {
+ let date = "2016/03/10 10:46:47";
+ let htmlTemplate = `{{ '${date}' | dateFormat }}`;
+ quickCreateComponent({ providers: [DateFormat], template: htmlTemplate }).then(fixture => {
+ expect(fixture.debugElement.text()).toEqual('2016-03-10T13:46:47.000Z');
+ done();
+ });
+ });
+
+ });
+});
diff --git a/src/app/shared/pipes/date-format.filter.ts b/src/app/shared/pipes/date-format.filter.ts
new file mode 100644
index 0000000..00ffa4d
--- /dev/null
+++ b/src/app/shared/pipes/date-format.filter.ts
@@ -0,0 +1,13 @@
+import {Pipe, Inject} from "ng-forward";
+
+@Pipe("dateFormat")
+@Inject("amParseFilter")
+export class DateFormat {
+
+ constructor(private amParseFilter: any) { }
+
+ transform(date: string, options: any) {
+ return this.amParseFilter(date, "YYYY/MM/DD HH:mm:ss").toISOString();
+ }
+
+}
diff --git a/src/app/shared/pipes/index.ts b/src/app/shared/pipes/index.ts
new file mode 100644
index 0000000..cf8498d
--- /dev/null
+++ b/src/app/shared/pipes/index.ts
@@ -0,0 +1,3 @@
+/* Module Index Entry - generated using the script npm run generate-index */
+export * from "./date-format.filter";
+export * from "./noosfero-template.filter";
diff --git a/src/app/shared/pipes/noosfero-template.filter.spec.ts b/src/app/shared/pipes/noosfero-template.filter.spec.ts
new file mode 100644
index 0000000..0e7b613
--- /dev/null
+++ b/src/app/shared/pipes/noosfero-template.filter.spec.ts
@@ -0,0 +1,19 @@
+import {quickCreateComponent} from "../../../spec/helpers";
+import {NoosferoTemplate} from './noosfero-template.filter';
+
+describe("Filters", () => {
+ describe("Noosfero Template Filter", () => {
+
+ beforeEach(angular.mock.module("templates"));
+
+ it("replace the options in text with the values passed on options", done => {
+ let text = 'profile: {profile}, other: {other}';
+ let htmlTemplate = `{{ '${text}' | noosferoTemplate: {profile: 'profile1', other: 'other value'} }}`;
+ quickCreateComponent({ providers: [NoosferoTemplate], template: htmlTemplate }).then(fixture => {
+ expect(fixture.debugElement.text()).toEqual("profile: profile1, other: other value");
+ done();
+ });
+ });
+
+ });
+});
diff --git a/src/app/shared/pipes/noosfero-template.filter.ts b/src/app/shared/pipes/noosfero-template.filter.ts
new file mode 100644
index 0000000..a7cd0df
--- /dev/null
+++ b/src/app/shared/pipes/noosfero-template.filter.ts
@@ -0,0 +1,13 @@
+import {Pipe} from "ng-forward";
+
+@Pipe("noosferoTemplate")
+export class NoosferoTemplate {
+
+ transform(text: string, options: any) {
+ for (let option in options) {
+ text = text.replace('{' + option + '}', options[option]);
+ }
+ return text;
+ }
+
+}
diff --git a/src/app/shared/services/index.ts b/src/app/shared/services/index.ts
new file mode 100644
index 0000000..151d498
--- /dev/null
+++ b/src/app/shared/services/index.ts
@@ -0,0 +1,3 @@
+/* Module Index Entry - generated using the script npm run generate-index */
+export * from "./notification.service";
+export * from "./translator.service";
diff --git a/src/app/shared/services/notification.service.spec.ts b/src/app/shared/services/notification.service.spec.ts
new file mode 100644
index 0000000..ea07a54
--- /dev/null
+++ b/src/app/shared/services/notification.service.spec.ts
@@ -0,0 +1,80 @@
+import {TestComponentBuilder, ComponentFixture} from 'ng-forward/cjs/testing/test-component-builder';
+import {Pipe, Input, provide, Component} from 'ng-forward';
+
+import * as helpers from "../../../spec/helpers";
+
+import {NotificationService} from "./notification.service";
+
+const tcb = new TestComponentBuilder();
+
+describe("Components", () => {
+
+ describe("Profile Image Component", () => {
+
+ beforeEach(angular.mock.module("templates"));
+
+ it("display an error message when notify an error", done => {
+ let sweetAlert = jasmine.createSpyObj("sweetAlert", ["swal"]);
+ sweetAlert.swal = jasmine.createSpy("swal");
+
+ let component: NotificationService = new NotificationService(helpers.mocks.$log, sweetAlert, helpers.mocks.translatorService);
+ component.error("message", "title");
+ expect(sweetAlert.swal).toHaveBeenCalledWith(jasmine.objectContaining({
+ text: "message",
+ title: "title",
+ type: "error"
+ }));
+ done();
+ });
+
+ it("use the default message when call notification component without a message", done => {
+ let sweetAlert = jasmine.createSpyObj("sweetAlert", ["swal"]);
+ sweetAlert.swal = jasmine.createSpy("swal");
+
+ let component: NotificationService = new NotificationService(helpers.mocks.$log, sweetAlert, helpers.mocks.translatorService);
+ component.error();
+ expect(sweetAlert.swal).toHaveBeenCalledWith(jasmine.objectContaining({
+ text: NotificationService.DEFAULT_ERROR_MESSAGE,
+ type: "error"
+ }));
+ done();
+ });
+
+ it("display a success message when call notification success", done => {
+ let sweetAlert = jasmine.createSpyObj("sweetAlert", ["swal"]);
+ sweetAlert.swal = jasmine.createSpy("swal");
+
+ let component: NotificationService = new NotificationService(helpers.mocks.$log, sweetAlert, helpers.mocks.translatorService);
+ component.success("title", "message", 1000);
+ expect(sweetAlert.swal).toHaveBeenCalledWith(jasmine.objectContaining({
+ type: "success"
+ }));
+ done();
+ });
+
+ it("display a message relative to the http error code", done => {
+ let sweetAlert = jasmine.createSpyObj("sweetAlert", ["swal"]);
+ sweetAlert.swal = jasmine.createSpy("swal");
+
+ let component: NotificationService = new NotificationService(helpers.mocks.$log, sweetAlert, helpers.mocks.translatorService);
+ component.httpError(500, {});
+ expect(sweetAlert.swal).toHaveBeenCalledWith(jasmine.objectContaining({
+ text: "notification.http_error.500.message"
+ }));
+ done();
+ });
+
+ it("set the default timer in success messages", done => {
+ let sweetAlert = jasmine.createSpyObj("sweetAlert", ["swal"]);
+ sweetAlert.swal = jasmine.createSpy("swal");
+
+ let component: NotificationService = new NotificationService(helpers.mocks.$log, sweetAlert, helpers.mocks.translatorService);
+ component.success("title", "message");
+ expect(sweetAlert.swal).toHaveBeenCalledWith(jasmine.objectContaining({
+ type: "success",
+ timer: NotificationService.DEFAULT_SUCCESS_TIMER
+ }));
+ done();
+ });
+ });
+});
diff --git a/src/app/shared/services/notification.service.ts b/src/app/shared/services/notification.service.ts
new file mode 100644
index 0000000..23a8bee
--- /dev/null
+++ b/src/app/shared/services/notification.service.ts
@@ -0,0 +1,41 @@
+import {Injectable, Inject} from "ng-forward";
+import {TranslatorService} from "./translator.service";
+
+@Injectable()
+@Inject("$log", "SweetAlert", TranslatorService)
+export class NotificationService {
+
+ constructor(
+ private $log: ng.ILogService,
+ private SweetAlert: any,
+ private translatorService: TranslatorService
+ ) { }
+
+ public static DEFAULT_ERROR_TITLE = "notification.error.default.title";
+ public static DEFAULT_ERROR_MESSAGE = "notification.error.default.message";
+ public static DEFAULT_SUCCESS_TIMER = 1000;
+
+ error(message: string = NotificationService.DEFAULT_ERROR_MESSAGE, title: string = NotificationService.DEFAULT_ERROR_TITLE) {
+ this.$log.debug("Notification error:", title, message, this.translatorService.currentLanguage());
+ this.SweetAlert.swal({
+ title: this.translatorService.translate(title),
+ text: this.translatorService.translate(message),
+ type: "error"
+ });
+ }
+
+ httpError(status: number, data: any): boolean {
+ this.error(`notification.http_error.${status}.message`);
+ return true; // return true to indicate that the error was already handled
+ }
+
+ success(title: string, text: string, timer: number = NotificationService.DEFAULT_SUCCESS_TIMER) {
+ this.SweetAlert.swal({
+ title: title,
+ text: text,
+ type: "success",
+ timer: timer
+ });
+ }
+
+}
diff --git a/src/app/shared/services/translator.service.spec.ts b/src/app/shared/services/translator.service.spec.ts
new file mode 100644
index 0000000..d1fee49
--- /dev/null
+++ b/src/app/shared/services/translator.service.spec.ts
@@ -0,0 +1,116 @@
+import {ComponentFixture} from 'ng-forward/cjs/testing/test-component-builder';
+import {provide} from 'ng-forward';
+
+import {TranslatorService} from './translator.service';
+
+import * as helpers from "../../../spec/helpers";
+
+describe("Services", () => {
+
+ describe("Translator Service", () => {
+
+ let $rootScope: ng.IScope;
+ let $q: ng.IQService;
+
+ beforeEach(inject((_$rootScope_: ng.IRootScopeService, _$q_: ng.IQService) => {
+ $rootScope = _$rootScope_;
+ $q = _$q_;
+ }));
+
+ function createComponent() {
+ return new TranslatorService(
+ helpers.mocks.$translate,
+ helpers.mocks.tmhDynamicLocale,
+ helpers.mocks.amMoment,
+ helpers.mocks.angularLoad,
+ $rootScope
+ );
+ }
+
+ it("set available languages when change language", (done) => {
+ let component: TranslatorService = createComponent();
+ component.availableLanguages = null;
+ expect(component.availableLanguages).toBeNull();
+ $rootScope.$emit("$translateChangeSuccess");
+ expect(component.availableLanguages).not.toBeNull();
+ done();
+ });
+
+ it("change the language", (done) => {
+ let component: TranslatorService = createComponent();
+ let loadScripPromise = $q.defer();
+ loadScripPromise.resolve();
+ component["angularLoad"].loadScript = jasmine.createSpy("loadScript").and.returnValue(loadScripPromise.promise);
+ component["tmhDynamicLocale"].set = jasmine.createSpy("set");
+ component["tmhDynamicLocale"].get = jasmine.createSpy("get").and.returnValue("en");
+ component["$translate"].use = jasmine.createSpy("use");
+
+ component.changeLanguage('pt');
+ $rootScope.$digest();
+
+ expect(component["angularLoad"].loadScript).toHaveBeenCalledWith("/bower_components/moment/locale/pt.js");
+ expect(component["angularLoad"].loadScript).toHaveBeenCalledWith("/bower_components/messageformat/locale/pt.js");
+ expect(component["tmhDynamicLocale"].set).toHaveBeenCalledWith("pt");
+ expect(component["$translate"].use).toHaveBeenCalledWith("pt");
+ done();
+ });
+
+ it("do not load moment locale when change the language to english", (done) => {
+ let component: TranslatorService = createComponent();
+ component["angularLoad"].loadScript = jasmine.createSpy("loadScript").and.returnValue($q.defer().promise);
+ component.changeLanguage('en');
+ expect(component["angularLoad"].loadScript).not.toHaveBeenCalledWith("/bower_components/moment/locale/pt.js");
+ done();
+ });
+
+ it("do nothing when call change language with null", (done) => {
+ let component: TranslatorService = createComponent();
+ component["angularLoad"].loadScript = jasmine.createSpy("loadScript");
+ component["tmhDynamicLocale"].set = jasmine.createSpy("set");
+ component["$translate"].use = jasmine.createSpy("use");
+
+ component.changeLanguage(null);
+
+ expect(component["angularLoad"].loadScript).not.toHaveBeenCalled();
+ expect(component["tmhDynamicLocale"].set).not.toHaveBeenCalled();
+ expect(component["$translate"].use).not.toHaveBeenCalled();
+ done();
+ });
+
+ it("return the current language used by the translator", (done) => {
+ let component: TranslatorService = createComponent();
+ component["$translate"].use = jasmine.createSpy("use").and.returnValue("en");
+ expect(component.currentLanguage()).toEqual("en");
+ expect(component["$translate"].use).toHaveBeenCalled();
+ done();
+ });
+
+ it("call translate service when translate a text", (done) => {
+ let component: TranslatorService = createComponent();
+ component["$translate"].instant = jasmine.createSpy("instant");
+ component.translate("text");
+ expect(component["$translate"].instant).toHaveBeenCalledWith("text");
+ done();
+ });
+
+ it("change the language when receive an event", (done) => {
+ let component: TranslatorService = createComponent();
+ component.changeLanguage = jasmine.createSpy("changeLanguage");
+ $rootScope.$emit("$localeChangeSuccess");
+ expect(component.changeLanguage).toHaveBeenCalled();
+ done();
+ });
+
+ it("use the translate language when receive a change language event and there is no language previously selected", (done) => {
+ let component: TranslatorService = createComponent();
+ component.changeLanguage = jasmine.createSpy("changeLanguage");
+ component["tmhDynamicLocale"].get = jasmine.createSpy("get").and.returnValue(null);
+ component["$translate"].use = jasmine.createSpy("use").and.returnValue("en");
+
+ $rootScope.$emit("$localeChangeSuccess");
+ expect(component["$translate"].use).toHaveBeenCalled();
+ expect(component.changeLanguage).toHaveBeenCalledWith("en");
+ done();
+ });
+ });
+});
diff --git a/src/app/shared/services/translator.service.ts b/src/app/shared/services/translator.service.ts
new file mode 100644
index 0000000..c2ee0fa
--- /dev/null
+++ b/src/app/shared/services/translator.service.ts
@@ -0,0 +1,59 @@
+import {Injectable, Inject} from "ng-forward";
+
+@Injectable()
+@Inject("$translate", "tmhDynamicLocale", "amMoment", "angularLoad", "$rootScope")
+export class TranslatorService {
+
+ availableLanguages: any;
+
+ constructor(private $translate: angular.translate.ITranslateService,
+ private tmhDynamicLocale: angular.dynamicLocale.tmhDynamicLocaleService,
+ private amMoment: any,
+ private angularLoad: any,
+ private $rootScope: any) {
+
+ this.$rootScope.$on("$localeChangeSuccess", () => {
+ this.changeLanguage(tmhDynamicLocale.get() || $translate.use());
+ });
+ this.$rootScope.$on("$translateChangeSuccess", () => {
+ this.configAvailableLanguages();
+ });
+ }
+
+ currentLanguage() {
+ return this.$translate.use();
+ }
+
+ changeLanguage(language: string) {
+ if (!language) {
+ console.log("WARN: language undefined");
+ return;
+ }
+ this.changeMomentLocale(language);
+ this.tmhDynamicLocale.set(language);
+ this.angularLoad.loadScript(`/bower_components/messageformat/locale/${language}.js`).then(() => {
+ return this.$translate.use(language);
+ });
+ }
+
+ translate(text: string) {
+ return this.$translate.instant(text);
+ }
+
+ private configAvailableLanguages() {
+ this.availableLanguages = {
+ "en": this.$translate.instant("language.en"),
+ "pt": this.$translate.instant("language.pt")
+ };
+ }
+
+ private changeMomentLocale(language: string) {
+ let localePromise = Promise.resolve();
+ if (language !== "en") {
+ localePromise = this.angularLoad.loadScript(`/bower_components/moment/locale/${language}.js`);
+ }
+ localePromise.then(() => {
+ this.amMoment.changeLocale(language);
+ });
+ }
+}
--
libgit2 0.21.2