diff --git a/scripts/langindex.json b/scripts/langindex.json index 5351ef509..89bf47b41 100644 --- a/scripts/langindex.json +++ b/scripts/langindex.json @@ -1793,6 +1793,7 @@ "core.submit": "moodle", "core.success": "moodle", "core.tablet": "local_moodlemobileapp", + "core.tag.tags": "moodle", "core.teachers": "moodle", "core.thereisdatatosync": "local_moodlemobileapp", "core.thisdirection": "langconfig", diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 6969e01bc..f908025de 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -81,6 +81,7 @@ import { CoreQuestionModule } from '@core/question/question.module'; import { CoreCommentsModule } from '@core/comments/comments.module'; import { CoreBlockModule } from '@core/block/block.module'; import { CoreRatingModule } from '@core/rating/rating.module'; +import { CoreTagModule } from '@core/tag/tag.module'; // Addon modules. import { AddonBadgesModule } from '@addon/badges/badges.module'; @@ -223,6 +224,7 @@ export const CORE_PROVIDERS: any[] = [ CoreBlockModule, CoreRatingModule, CorePushNotificationsModule, + CoreTagModule, AddonBadgesModule, AddonBlogModule, AddonCalendarModule, diff --git a/src/assets/lang/en.json b/src/assets/lang/en.json index 21810db95..0dc92ff13 100644 --- a/src/assets/lang/en.json +++ b/src/assets/lang/en.json @@ -1793,6 +1793,7 @@ "core.submit": "Submit", "core.success": "Success", "core.tablet": "Tablet", + "core.tag.tags": "Tags", "core.teachers": "Teachers", "core.thereisdatatosync": "There are offline {{$a}} to be synchronised.", "core.thisdirection": "ltr", diff --git a/src/core/tag/components/components.module.ts b/src/core/tag/components/components.module.ts new file mode 100644 index 000000000..c2e07f85b --- /dev/null +++ b/src/core/tag/components/components.module.ts @@ -0,0 +1,40 @@ +// (C) Copyright 2015 Martin Dougiamas +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { IonicModule } from 'ionic-angular'; +import { TranslateModule } from '@ngx-translate/core'; +import { CoreTagListComponent } from './list/list'; +import { CoreDirectivesModule } from '@directives/directives.module'; + +@NgModule({ + declarations: [ + CoreTagListComponent + ], + imports: [ + CommonModule, + IonicModule, + CoreDirectivesModule, + TranslateModule.forChild() + ], + providers: [ + ], + exports: [ + CoreTagListComponent + ], + entryComponents: [ + ] +}) +export class CoreTagComponentsModule {} diff --git a/src/core/tag/components/list/core-tag-list.html b/src/core/tag/components/list/core-tag-list.html new file mode 100644 index 000000000..7e6372e20 --- /dev/null +++ b/src/core/tag/components/list/core-tag-list.html @@ -0,0 +1,3 @@ + + {{ tag.rawname }} + diff --git a/src/core/tag/components/list/list.scss b/src/core/tag/components/list/list.scss new file mode 100644 index 000000000..569d645d6 --- /dev/null +++ b/src/core/tag/components/list/list.scss @@ -0,0 +1,7 @@ +ion-app.app-root core-tag-list { + line-height: 1.6; + + ion-badge { + cursor: pointer; + } +} diff --git a/src/core/tag/components/list/list.ts b/src/core/tag/components/list/list.ts new file mode 100644 index 000000000..6abbf3d7f --- /dev/null +++ b/src/core/tag/components/list/list.ts @@ -0,0 +1,45 @@ +// (C) Copyright 2015 Martin Dougiamas +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import { Component, Input, Optional } from '@angular/core'; +import { NavController } from 'ionic-angular'; +import { CoreTagItem } from '@core/tag/providers/tag'; +import { CoreSplitViewComponent } from '@components/split-view/split-view'; + +/** + * Component that displays the list of tags of an item. + */ +@Component({ + selector: 'core-tag-list', + templateUrl: 'core-tag-list.html' +}) +export class CoreTagListComponent { + @Input() tags: CoreTagItem[]; + + constructor(private navCtrl: NavController, @Optional() private svComponent: CoreSplitViewComponent) {} + + /** + * Go to tag index page. + */ + openTag(tag: CoreTagItem): void { + const navCtrl = this.svComponent ? this.svComponent.getMasterNav() : this.navCtrl; + const params = { + tagId: tag.id, + tagName: tag.rawname, + collectionId: tag.tagcollid, + fromContextId: tag.taginstancecontextid + }; + navCtrl.push('CoreTagIndexPage', params); + } +} diff --git a/src/core/tag/lang/en.json b/src/core/tag/lang/en.json new file mode 100644 index 000000000..fec56bb36 --- /dev/null +++ b/src/core/tag/lang/en.json @@ -0,0 +1,3 @@ +{ + "tags": "Tags" +} diff --git a/src/core/tag/providers/tag.ts b/src/core/tag/providers/tag.ts new file mode 100644 index 000000000..fdcdaf189 --- /dev/null +++ b/src/core/tag/providers/tag.ts @@ -0,0 +1,70 @@ +// (C) Copyright 2015 Martin Dougiamas +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import { Injectable } from '@angular/core'; +import { CoreSitesProvider } from '@providers/sites'; +import { CoreSite } from '@classes/site'; + +/** + * Structure of a tag item returned by WS. + */ +export interface CoreTagItem { + id: number; + name: string; + rawname: string; + isstandard: boolean; + tagcollid: number; + taginstanceid: number; + taginstancecontextid: number; + itemid: number; + ordering: number; + flag: number; +} + +/** + * Service to handle tags. + */ +@Injectable() +export class CoreTagProvider { + + constructor(private sitesProvider: CoreSitesProvider) {} + + /** + * Check whether tags are available in a certain site. + * + * @param {string} [siteId] Site Id. If not defined, use current site. + * @return {Promise} Promise resolved with true if available, resolved with false otherwise. + * @since 3.7 + */ + areTagsAvailable(siteId?: string): Promise { + return this.sitesProvider.getSite(siteId).then((site) => { + return this.areTagsAvailableInSite(site); + }); + } + + /** + * Check whether tags are available in a certain site. + * + * @param {CoreSite} [site] Site. If not defined, use current site. + * @return {boolean} True if available. + */ + areTagsAvailableInSite(site?: CoreSite): boolean { + site = site || this.sitesProvider.getCurrentSite(); + + return site.wsAvailable('core_tag_get_tagindex_per_area') && + site.wsAvailable('core_tag_get_tag_cloud') && + site.wsAvailable('core_tag_get_tag_collections') && + !site.isFeatureDisabled('NoDelegate_CoreTag'); + } +} diff --git a/src/core/tag/tag.module.ts b/src/core/tag/tag.module.ts new file mode 100644 index 000000000..eaa2f9e81 --- /dev/null +++ b/src/core/tag/tag.module.ts @@ -0,0 +1,28 @@ +// (C) Copyright 2015 Martin Dougiamas +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import { NgModule } from '@angular/core'; +import { CoreTagProvider } from './providers/tag'; + +@NgModule({ + declarations: [ + ], + imports: [ + ], + providers: [ + CoreTagProvider, + ] +}) +export class CoreTagModule { +}