/** * @return mixed */ public function getRedirectUrl() { if ($this->isEditing()) { return $this->getModel()->to('edit'); } $tag = new Model\Tag(); return $tag->to('new'); }
/** * @param FunctionalTester $I * * @actor FunctionalTester * * @return void */ public function addTag(FunctionalTester $I) { $I->am('Admin User'); $I->wantTo('add new tag'); $tag = new Tag(); $group = $tag->getGroups()->random(1); $data = ['name' => 'tag1', 'group' => $group->id, 'bgcolor' => 'red']; $I->amLoggedAs($I->createUser(1, 4)); $I->amOnAction('Administration\\TagsController@getNew'); $I->submitForm('form', $data); $I->seeCurrentActionIs('Administration\\TagsController@getIndex'); $I->seeRecord($tag->getTable(), $data); }
/** * Run the migrations. * * @return void */ public function up() { if (!Schema::hasTable('tags')) { Schema::create('tags', function (Blueprint $table) { $table->increments('id')->unsigned(); $table->bigInteger('parent_id')->default(0); $table->string('name', 255)->unique(); $table->string('bgcolor', 50)->nullable(); $table->boolean('group'); $table->timestamps(); }); $groups = ['status', 'type', 'resolution']; foreach ($groups as $group) { $model = new Model\Tag(); $model->name = $group; $model->group = true; $model->save(); } $tags = [['name' => 'open', 'parent_id' => 'status', 'bgcolor' => '#c43c35'], ['name' => 'testing', 'parent_id' => 'status', 'bgcolor' => '#6c8307'], ['name' => 'closed', 'parent_id' => 'status', 'bgcolor' => '#46a546'], ['name' => 'feature', 'parent_id' => 'type', 'bgcolor' => '#62cffc'], ['name' => 'bug', 'parent_id' => 'type', 'bgcolor' => '#f89406'], ['name' => 'won\'t fix', 'parent_id' => 'resolution', 'bgcolor' => '#812323'], ['name' => 'fixed', 'parent_id' => 'resolution', 'bgcolor' => '#048383']]; foreach ($tags as $tag) { $model = new Model\Tag(); $model->name = $tag['name']; $model->bgcolor = $tag['bgcolor']; $model->parent_id = Model\Tag::where('name', '=', $tag['parent_id'])->first()->id; $model->group = false; $model->save(); } } if (!Schema::hasTable('projects_issues_tags')) { Schema::create('projects_issues_tags', function (Blueprint $table) { $table->bigInteger('issue_id'); $table->bigInteger('tag_id'); $table->primary(['issue_id', 'tag_id']); }); } $openIssues = Model\Project\Issue::where('status', '=', Model\Project\Issue::STATUS_OPEN)->lists('id'); if (count($openIssues) > 0) { $openTag = Model\Tag::where('parent_id', '=', Model\Tag::where('name', '=', 'status')->first()->id)->where('name', '=', 'open')->first(); $openTag->issues()->attach($openIssues); } $closedIssues = Model\Project\Issue::where('status', '=', Model\Project\Issue::STATUS_CLOSED)->lists('id'); if (count($closedIssues) > 0) { $closedTag = Model\Tag::where('parent_id', '=', Model\Tag::where('name', '=', 'status')->first()->id)->where('name', '=', 'closed')->first(); $closedTag->issues()->attach($closedIssues); } // Create activity type for tag update $activity = new Model\Activity(); $activity->description = 'Updated issue tags'; $activity->activity = 'update-issue-tags'; $activity->save(); }
/** * Create a new tag if valid or return existing one * * @param string $name * @param null|Tag $parent * * @return bool|$this */ public function validOrCreate($name, Tag $parent = null) { $group = $parent === null ? true : false; $tag = $this->where('name', '=', $name)->first(); if ($tag && $tag->group != $group) { return false; } if (!$tag) { $tag = new Tag(); $tag->name = $name; $tag->group = $group; if (!is_null($parent)) { $tag->parent_id = $parent->id; $tag->setRelation('parent', $parent); } $tag->save(); } return $tag; }
/** * @param FunctionalTester\UserSteps $I * * @actor FunctionalTester\UserSteps * * @return void */ public function exportByTags(FunctionalTester\UserSteps $I) { $I->am('Admin User'); $I->wantTo('Export a project issues by tag into CSV file'); list($manager, $project, $issues1, $issues2, $developer) = $this->_createData($I, true); $I->login($manager->email, '123', $manager->firstname); // Add tag to issues1 $I->sendAjaxGetRequest($I->getApplication()->url->action('Administration\\TagsController@getTags', ['term' => 'f'])); $tags = new Collection((array) $I->getJsonResponseContent()); $tags = $tags->filter(function ($tag) use($I) { return strpos(strtolower($tag->label), ':feature') !== false; }); array_walk($issues1, function ($issue) use($I, $tags) { foreach ($tags as $tag) { $issue->tags()->save(Tag::find($tag->value)); } }); $this->_exportIssues($I, $project, ['assignto' => $developer->id, 'tags' => $tags->implode('value', ',')]); $this->_downloadExport($I, $project); $this->_assertExport($I, $project, $issues1, $issues2); }
/** * Show general application stats * * @param Tag $tag * @param Project $project * @param User $user * * @return \Illuminate\View\View */ public function getIndex(Tag $tag, Project $project, User $user) { return view('administration.index', ['users' => $user->countUsers(), 'active_projects' => $project->countOpenProjects(), 'archived_projects' => $project->countArchivedProjects(), 'open_issues' => $project->countOpenIssues(), 'closed_issues' => $project->countClosedIssues(), 'projects' => $this->auth->user()->projects()->get(), 'tags' => $tag->count()]); }
/** * Ajax: to search for tag by keyword (used by auto complete tag field) * * @param Tag $tag * @param string $term * @param Request $request * * @return \Symfony\Component\HttpFoundation\Response */ public function getTags(Tag $tag, Request $request, $term = '') { $tags = []; $term = (string) $request->input('term', $term); if (!empty($term)) { $tags = $tag->searchTags($term)->filter(function (Tag $tag) { return !($tag->name == 'open' || $tag->name == 'closed'); })->map(function (Tag $tag) { return ['value' => $tag->id, 'label' => $tag->fullname, 'bgcolor' => $tag->bgcolor]; })->toArray(); } return response()->json($tags); }
/** * Create new tags from a string "group:tag_name" and fetch tag from a tag id. * * @param array $tags * @param bool $isAdmin * * @return Collection */ protected function createTags(array $tags, $isAdmin = false) { $newTags = new Collection($tags); // Transform the user input tags into tag objects $newTags->transform(function ($tagNameOrId) use($isAdmin) { if (strpos($tagNameOrId, ':') !== false && $isAdmin) { return (new Tag())->createTagFromString($tagNameOrId); } else { return Tag::find($tagNameOrId); } }); // Filter out invalid tags entered by the user $newTags = $newTags->filter(function ($tag) { return $tag instanceof Tag; }); return $newTags; }
/** * Returns issue tags except for the status tags * * @return Eloquent\Collection */ public function getTagsExceptStatus() { $statusGroup = Tag::where('name', '=', Tag::GROUP_STATUS)->first(); return $this->tags()->where('parent_id', '!=', $statusGroup->id); }