Skip to content
This repository has been archived by the owner on Nov 19, 2021. It is now read-only.

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
jbarrett committed Feb 20, 2015
2 parents d35b5f9 + fd0eb80 commit a47f3d0
Show file tree
Hide file tree
Showing 34 changed files with 496 additions and 76 deletions.
1 change: 1 addition & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ module.exports = function(grunt) {
var ia_page_js = [
'handlebars_tmp',
'DDH.js',
'IADevPipeline.js',
'IAIndex.js',
'IAPage.js',
'IAPageCommit.js',
Expand Down
4 changes: 2 additions & 2 deletions lib/DDGC/DB/Result/Help.pm
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ unique_column key => {

column help_category_id => {
data_type => 'bigint',
is_nullable => 0,
is_nullable => 1,
};

belongs_to 'help_category', 'DDGC::DB::Result::Help::Category', 'help_category_id';
belongs_to 'help_category', 'DDGC::DB::Result::Help::Category', 'help_category_id', { join_type => 'left' };;
sub category { shift->help_category(@_) }

column data => {
Expand Down
2 changes: 1 addition & 1 deletion lib/DDGC/DB/Result/InstantAnswer/Topics.pm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ column topics_id => {
primary_key (qw/instant_answer_id topics_id/);

belongs_to 'instant_answer', 'DDGC::DB::Result::InstantAnswer', 'instant_answer_id', {on_delete => 'cascade'};
belongs_to 'topic', 'DDGC::DB::Result::Topic', 'topics_id';
belongs_to 'topic', 'DDGC::DB::Result::Topic', 'topics_id', {on_delete => 'cascade'};

no Moose;
__PACKAGE__->meta->make_immutable;
2 changes: 1 addition & 1 deletion lib/DDGC/DB/Result/Topic.pm
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ unique_column name => {
is_nullable => 0,
};

has_many 'instant_answer_topics', 'DDGC::DB::Result::InstantAnswer::Topics', 'topics_id';
has_many 'instant_answer_topics', 'DDGC::DB::Result::InstantAnswer::Topics', 'topics_id', {on_delete => 'cascade'};
many_to_many 'instant_answers', 'instant_answer_topics', 'instant_answer';

no Moose;
Expand Down
1 change: 1 addition & 0 deletions lib/DDGC/Web/Controller/Admin/Help.pm
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ sub index :Chained('base') :PathPart('') :Args(0) {
if ($id > 0) {
$help = $c->d->rs('Help')->find($id);
die "help id ".$_." not found" unless $help;
$help_values{help_category_id} ||= undef;
for (keys %help_values) {
$help->$_($help_values{$_});
}
Expand Down
173 changes: 141 additions & 32 deletions lib/DDGC/Web/Controller/InstantAnswer.pm
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,37 @@ sub base :Chained('/base') :PathPart('ia') :CaptureArgs(0) {
my ( $self, $c ) = @_;
}

sub index :Chained('base') :PathPart('') :Args() {
my ( $self, $c, $field, $value ) = @_;
sub index :Chained('base') :PathPart('') :Args(0) {
my ( $self, $c ) = @_;
# Retrieve / stash all IAs for index page here?

# my @x = $c->d->rs('InstantAnswer')->all();
# $c->stash->{ialist} = \@x;
$c->stash->{ia_page} = "IAIndex";

if ($field && $value) {
$c->stash->{field} = $field;
$c->stash->{value} = $value;
}
#if ($field && $value) {
# $c->stash->{field} = $field;
# $c->stash->{value} = $value;
#}

my $rs = $c->d->rs('Topic');

my @topics = $rs->search(
{'name' => { '!=' => 'test' }},
{
columns => [ qw/ name id /],
order_by => [ qw/ name /],
result_class => 'DBIx::Class::ResultClass::HashRefInflator',
}
)->all;

my $is_admin;

if ($c->user) {
$is_admin = $c->user->admin;
}

$c->stash->{admin} = $is_admin;
$c->stash->{title} = "Index: Instant Answers";
$c->stash->{topic_list} = \@topics;
$c->add_bc('Instant Answers', $c->chained_uri('InstantAnswer','index'));
Expand All @@ -46,18 +54,17 @@ sub index :Chained('base') :PathPart('') :Args() {
}

sub ialist_json :Chained('base') :PathPart('json') :Args() {
my ( $self, $c, $field, $value ) = @_;

my $rs;
my ( $self, $c ) = @_;

if ($field && $value) {
$rs = $c->d->rs('InstantAnswer')->search_rs({$field => $value});
} else {
$rs = $c->d->rs('InstantAnswer');
}
my $rs = $c->d->rs('InstantAnswer');

my @ial = $rs->search(
{'topic.name' => { '!=' => 'test' }},
{'topic.name' => { '!=' => 'test' },
-or => [
'me.dev_milestone' => { '=' => 'live'},
'me.dev_milestone' => { '=' => 'ready'},
],
},
{
columns => [ qw/ name id repo src_name dev_milestone description template / ],
prefetch => { instant_answer_topics => 'topic' },
Expand Down Expand Up @@ -104,7 +111,7 @@ sub iarepo_json :Chained('iarepo') :PathPart('json') :Args(0) {

my $src_options = $ia->src_options;
if ($src_options ) {
$iah{$ia->id}{src_options} = decode_json($src_options);
$iah{$ia->id}{src_options} = from_json($src_options);
}

$iah{$ia->id}{src_id} = $ia->src_id if $ia->src_id;
Expand All @@ -121,6 +128,70 @@ sub queries :Chained('base') :PathPart('queries') :Args(0) {

}

sub dev_pipeline_base :Chained('base') :PathPart('pipeline') :CaptureArgs(0) {
my ( $self, $c ) = @_;
}

sub dev_pipeline :Chained('dev_pipeline_base') :PathPart('') :Args(0) {
my ( $self, $c ) = @_;

$c->stash->{ia_page} = "IADevPipeline";
$c->stash->{title} = "Dev Pipeline";
$c->add_bc('Instant Answers', $c->chained_uri('InstantAnswer','index'));
$c->add_bc('Dev Pipeline', $c->chained_uri('InstantAnswer','dev_pipeline'));
}

sub dev_pipeline_json :Chained('dev_pipeline_base') :PathPart('json') :Args(0) {
my ( $self, $c ) = @_;

my $rs = $c->d->rs('InstantAnswer');
my @planning = $rs->search(
{'me.dev_milestone' => { '=' => 'planning'}},
{
columns => [ qw/ name id dev_milestone/ ],
order_by => [ qw/ name/ ],
result_class => 'DBIx::Class::ResultClass::HashRefInflator',
}
)->all;

my @in_development = $rs->search(
{'me.dev_milestone' => { '=' => 'in_development'}},
{
columns => [ qw/ name id dev_milestone/ ],
order_by => [ qw/ name/ ],
result_class => 'DBIx::Class::ResultClass::HashRefInflator',
}
)->all;

my @qa = $rs->search(
{'me.dev_milestone' => { '=' => 'qa'}},
{
columns => [ qw/ name id dev_milestone/ ],
order_by => [ qw/ name/ ],
result_class => 'DBIx::Class::ResultClass::HashRefInflator',
}
)->all;

my @ready = $rs->search(
{'me.dev_milestone' => { '=' => 'ready'}},
{
columns => [ qw/ name id dev_milestone/ ],
order_by => [ qw/ name/ ],
result_class => 'DBIx::Class::ResultClass::HashRefInflator',
}
)->all;

$c->stash->{x} = {
planning => \@planning,
in_development => \@in_development,
qa => \@qa,
ready => \@ready,
};

$c->stash->{not_last_url} = 1;
$c->forward($c->view('JSON'));
}

sub ia_base :Chained('base') :PathPart('view') :CaptureArgs(1) { # /ia/view/calculator
my ( $self, $c, $answer_id ) = @_;

Expand Down Expand Up @@ -196,20 +267,20 @@ sub ia_json :Chained('ia_base') :PathPart('json') :Args(0) {
id => $issue->issue_id,
title => $issue->title,
body => $issue->body,
tags => $issue->tags? decode_json($issue->tags) : undef
tags => $issue->tags? from_json($issue->tags) : undef
);
} else {
push(@ia_issues, {
issue_id => $issue->issue_id,
title => $issue->title,
body => $issue->body,
tags => $issue->tags? decode_json($issue->tags) : undef
tags => $issue->tags? from_json($issue->tags) : undef
});
}
}
}

my $other_queries = $ia->other_queries? decode_json($ia->other_queries) : undef;
my $other_queries = $ia->other_queries? from_json($ia->other_queries) : undef;

$ia_data{live} = {
id => $ia->id,
Expand All @@ -222,9 +293,9 @@ sub ia_json :Chained('ia_base') :PathPart('json') :Args(0) {
perl_module => $ia->perl_module,
example_query => $ia->example_query,
other_queries => $other_queries,
code => $ia->code? decode_json($ia->code) : undef,
code => $ia->code? from_json($ia->code) : undef,
topic => \@topics,
attribution => $ia->attribution? decode_json($ia->attribution) : undef,
attribution => $ia->attribution? from_json($ia->attribution) : undef,
issues => \@ia_issues,
pr => \%pull_request,
template => $ia->template,
Expand All @@ -233,8 +304,8 @@ sub ia_json :Chained('ia_base') :PathPart('json') :Args(0) {
producer => $ia->producer,
designer => $ia->designer,
developer => $ia->developer,
perl_dependencies => $ia->perl_dependencies? decode_json($ia->perl_dependencies) : undef,
triggers => $ia->triggers? decode_json($ia->triggers) : undef,
perl_dependencies => $ia->perl_dependencies? from_json($ia->perl_dependencies) : undef,
triggers => $ia->triggers? from_json($ia->triggers) : undef,
code_review => $ia->code_review,
design_review => $ia->design_review,
test_machine => $ia->test_machine,
Expand Down Expand Up @@ -310,7 +381,7 @@ sub commit_json :Chained('commit_base') :PathPart('json') :Args(0) {
status => $ia->status,
topic => \@topics,
example_query => $ia->example_query,
other_queries => $ia->other_queries? decode_json($ia->other_queries) : undef,
other_queries => $ia->other_queries? from_json($ia->other_queries) : undef,
dev_milestone => $ia->dev_milestone
);

Expand All @@ -336,7 +407,7 @@ sub commit_save :Chained('commit_base') :PathPart('save') :Args(0) {

if ($is_admin) {
my $ia = $c->d->rs('InstantAnswer')->find($c->req->params->{id});
my @params = decode_json($c->req->params->{values});
my @params = from_json($c->req->params->{values});

for my $param (@params) {
for my $hash_param (@{$param}) {
Expand Down Expand Up @@ -368,7 +439,7 @@ sub commit_save :Chained('commit_base') :PathPart('save') :Args(0) {
}
} else {
if ($field eq 'other_queries') {
$value = encode_json($value);
$value = to_json($value);
}

try {
Expand Down Expand Up @@ -412,7 +483,7 @@ sub save_edit :Chained('base') :PathPart('save') :Args(0) {
my $autocommit = $c->req->params->{autocommit};
if ($autocommit) {
if ($field eq "topic") {
my @topic_values = $value? decode_json($value) : undef;
my @topic_values = $value? from_json($value) : undef;
$ia->instant_answer_topics->delete;

for my $topic (@{$topic_values[0]}) {
Expand Down Expand Up @@ -475,6 +546,44 @@ sub save_edit :Chained('base') :PathPart('save') :Args(0) {
return $c->forward($c->view('JSON'));
}

sub create_ia :Chained('base') :PathPart('create') :Args() {
my ( $self, $c ) = @_;

my $ia = $c->d->rs('InstantAnswer')->find({lc id => $c->req->params->{id}});
my $is_admin;
my $result = '';

if ($c->user && (!$ia)) {
$is_admin = $c->user->admin;

if ($is_admin) {
my $dev_milestone = $c->req->params->{dev_milestone};
my $status = $dev_milestone;

if ($dev_milestone eq 'in_development') {
$status =~ s/_/ /g;
}

my $new_ia = $c->d->rs('InstantAnswer')->create({
lc id => $c->req->params->{id},
name => $c->req->params->{name},
status => $status,
dev_milestone => $dev_milestone,
description => $c->req->params->{description},
});

$result = 1;
}
}

$c->stash->{x} = {
result => $result,
};

$c->stash->{not_last_url} = 1;
return $c->forward($c->view('JSON'));
}

# Return a hash with the latest edits for the given IA
sub current_ia {
my ($d, $ia) = @_;
Expand Down Expand Up @@ -502,14 +611,14 @@ sub current_ia {
# to see if this field was edited
my %other_q = (
edited => $other_q_edited,
value => $other_q_val? decode_json($other_q_val) : undef
value => $other_q_val? from_json($other_q_val) : undef
);

%x = (
name => $name[0][@name]{'value'},
description => $desc[0][@desc]{'value'},
status => $status[0][@status]{'value'},
topic => $topic_val? decode_json($topic_val) : undef,
topic => $topic_val? from_json($topic_val) : undef,
example_query => $example_query[0][@example_query]{'value'},
other_queries => \%other_q,
dev_milestone => $dev_milestone[0][@dev_milestone]{'value'}
Expand All @@ -529,7 +638,7 @@ sub add_edit {
my $current_updates = $ia->get_column('updates') || ();

if($value ne $orig_data){
$current_updates = $current_updates? decode_json($current_updates) : undef;
$current_updates = $current_updates? from_json($current_updates) : undef;
my @field_updates = $current_updates->{$field}? $current_updates->{$field} : undef;
my $time = time;
my %new_update = ( value => $value,
Expand Down Expand Up @@ -560,7 +669,7 @@ sub remove_edit {

my $updates = ();
my $column_updates = $ia->get_column('updates');
my $edits = $column_updates? decode_json($column_updates) : undef;
my $edits = $column_updates? from_json($column_updates) : undef;
$edits->{$field} = undef;

$ia->update({updates => $edits});
Expand All @@ -586,7 +695,7 @@ sub get_edits {

try{
my $column_updates = $ia_result->get_column('updates');
$edits = $column_updates? decode_json($column_updates) : undef;
$edits = $column_updates? from_json($column_updates) : undef;
}catch{
return;
};
Expand Down
2 changes: 1 addition & 1 deletion lib/DDGC/Web/Controller/Translate.pm
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ sub token :Chained('logged_in') :Args(1) {

for (keys %{$c->req->params}) {
if ($_ =~ m/token_notes_(\d+)_edit$/) {
my $token = $c->d->resultset('Token')->find($_);
my $token = $c->d->resultset('Token')->find($1);
$token->notes($c->req->params->{$_});
$token->update;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ddg_community_platform",
"version": "0.56.0",
"version": "0.57.0",
"engines": {
"node": ">=0.10.0"
},
Expand Down
1 change: 1 addition & 0 deletions root/static/css/ddgc0.56.0.css

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions root/static/css/ia0.56.0.css

Large diffs are not rendered by default.

Loading

0 comments on commit a47f3d0

Please sign in to comment.