[spalenque] - #6968 *WIP

This commit is contained in:
santipalenque 2014-11-04 12:41:48 -03:00 committed by Sebastian Marcet
parent 5094226753
commit 606f42d2e8
17 changed files with 418 additions and 28 deletions

View File

@ -36,6 +36,11 @@ final class CompanyServiceAssembler {
array_push($videos,MarketPlaceAssembler::convertVideo2Array($video)); array_push($videos,MarketPlaceAssembler::convertVideo2Array($video));
} }
$res['videos'] = $videos; $res['videos'] = $videos;
//draft
if($company_service->isDraft()) {
$res['live_service_id'] = $company_service->getLiveServiceId();
}
return $res; return $res;
} }

View File

@ -40,6 +40,8 @@ final class OpenStackImplementationAssembler {
array_push($guest_os,$guest->getIdentifier()); array_push($guest_os,$guest->getIdentifier());
} }
$res['guest_os'] = $guest_os; $res['guest_os'] = $guest_os;
//draft
if ($res)
return $res; return $res;
} }

View File

@ -61,6 +61,11 @@ class CompanyService
return null; return null;
} }
public function isDraft()
{
return false;
}
public function setCompany(ICompany $company) public function setCompany(ICompany $company)
{ {
AssociationFactory::getInstance()->getMany2OneAssociation($this,'Company')->setTarget($company); AssociationFactory::getInstance()->getMany2OneAssociation($this,'Company')->setTarget($company);

View File

@ -30,8 +30,8 @@ class CompanyServiceDraft
); );
static $has_many = array( static $has_many = array(
'Resources' => 'CompanyServiceResource', 'Resources' => 'CompanyServiceResourceDraft',
'Videos' => 'MarketPlaceVideo', 'Videos' => 'MarketPlaceVideoDraft',
); );
protected function onBeforeWrite() { protected function onBeforeWrite() {
@ -51,6 +51,11 @@ class CompanyServiceDraft
return null; return null;
} }
public function isDraft()
{
return true;
}
public function setCompany(ICompany $company) public function setCompany(ICompany $company)
{ {
AssociationFactory::getInstance()->getMany2OneAssociation($this,'Company')->setTarget($company); AssociationFactory::getInstance()->getMany2OneAssociation($this,'Company')->setTarget($company);
@ -75,6 +80,14 @@ class CompanyServiceDraft
$this->setField('LiveServiceID',$company_service_id); $this->setField('LiveServiceID',$company_service_id);
} }
/**
* @return int
*/
public function getLiveServiceId()
{
return (int)$this->getField('LiveServiceID');
}
/** /**
* @return int * @return int
*/ */

View File

@ -0,0 +1,81 @@
<?php
/**
* Class CompanyServiceResourceDraft
*/
class CompanyServiceResourceDraft extends DataObject implements ICompanyServiceResource {
static $create_table_options = array('MySQLDatabase' => 'ENGINE=InnoDB');
static $db = array(
'Name' => 'Varchar',
'Uri' => 'Text',
'Order' => 'Int',
);
static $has_one = array(
'Owner' => 'CompanyServiceDraft',
);
static $indexes = array(
'Owner_Name' => array('type'=>'unique', 'value'=>'Name, OwnerID')
);
public function getName()
{
return $this->getField('Name');
}
public function setName($name)
{
return $this->setField('Name', substr(trim($name),0,250));
}
public function getUri()
{
return $this->getField('Uri');
}
public function setUri($uri)
{
return $this->setField('Uri', trim($uri));
}
/**
* @return ICompanyService
*/
public function getOwner()
{
$query = new QueryObject($this);
$query->addOrder(QueryOrder::asc('Order'));
return AssociationFactory::getInstance()->getMany2OneAssociation($this,'Owner','Resources',$query)->getTarget();
}
/**
* @param ICompanyService $new_owner
*/
public function setOwner(ICompanyService $new_owner)
{
$query = new QueryObject($this);
$query->addOrder(QueryOrder::asc('Order'));
AssociationFactory::getInstance()->getMany2OneAssociation($this,'Owner','Resources',$query)->setTarget($new_owner);
}
/**
* @return int
*/
public function getIdentifier()
{
return (int)$this->getField('ID');
}
public function getOrder()
{
return (int)$this->getField('Order');
}
public function setOrder($order)
{
return $this->setField('Order', (int)$order);
}
}

View File

@ -0,0 +1,109 @@
<?php
/**
* Class MarketPlaceVideoDraft
*/
class MarketPlaceVideoDraft extends DataObject implements IMarketPlaceVideo {
static $create_table_options = array('MySQLDatabase' => 'ENGINE=InnoDB');
static $db = array(
'Name' => 'Text',
'Description' => 'Text',
'YouTubeID' => 'Text',
//seconds
'Length' => 'int',
);
static $has_one = array(
'Type' => 'MarketPlaceVideoType',
'Owner' => 'CompanyServiceDraft',
);
/**
* @return int
*/
public function getIdentifier()
{
return (int)$this->getField('ID');
}
/**
* @param IMarketPlaceVideoType $type
* @return void
*/
public function setType(IMarketPlaceVideoType $type)
{
AssociationFactory::getInstance()->getMany2OneAssociation($this,'Type')->setTarget($type);
}
/**
* @return IMarketPlaceVideoType
*/
public function getType()
{
return AssociationFactory::getInstance()->getMany2OneAssociation($this,'Type')->getTarget();
}
public function getName()
{
return $this->getField('Name');
}
public function setName($name)
{
$this->setField('Name',$name);
}
public function getDescription()
{
return $this->getField('Description');
}
public function setDescription($description)
{
$this->setField('Description',$description);
}
public function getLength()
{
return (int)$this->getField('Length');
}
public function setLength($length)
{
$this->setField('Length',$length);
}
public function setYouTubeId($you_tube_id)
{
$this->setField('YouTubeID',$you_tube_id);
}
public function getYouTubeId()
{
return $this->getField('YouTubeID');
}
/**
* @return ICompanyService
*/
public function getOwner()
{
return AssociationFactory::getInstance()->getMany2OneAssociation($this,'Owner','Videos')->getTarget();
}
/**
* @param ICompanyService $owner
* @return void
*/
public function setOwner(ICompanyService $owner)
{
AssociationFactory::getInstance()->getMany2OneAssociation($this,'Owner','Videos')->setTarget($owner);
}
public function getFormattedLength()
{
$len = $this->getLength();
return sprintf('%02d', floor($len / 60)).sprintf(':%02d', (int) $len % 60);
}
}

View File

@ -24,7 +24,6 @@ class OpenStackImplementation
); );
static $has_many = array( static $has_many = array(
'RegionalSupports' => 'RegionalSupport',
'Capabilities' => 'OpenStackImplementationApiCoverage' 'Capabilities' => 'OpenStackImplementationApiCoverage'
); );

View File

@ -0,0 +1,91 @@
<?php
/**
* Class OpenStackImplementationApiCoverageDraft
*/
class OpenStackImplementationApiCoverageDraft
extends DataObject
implements IOpenStackImplementationApiCoverage {
static $create_table_options = array('MySQLDatabase' => 'ENGINE=InnoDB');
static $db = array(
'CoveragePercent' => 'Int',
);
static $has_one = array(
'Implementation' => 'OpenStackImplementationDraft',
'ReleaseSupportedApiVersion' => 'OpenStackReleaseSupportedApiVersion',
);
/**
* @return int
*/
public function getIdentifier()
{
return (int)$this->getField('ID');
}
/**
* @return int
*/
public function getCoveragePercent()
{
return (int)$this->getField('CoveragePercent');
}
/**
* @param int $coverage
* @return void
*/
public function setCoveragePercent($coverage)
{
$this->setField('CoveragePercent',$coverage);
}
/**
* @return IOpenStackImplementation
*/
public function getImplementation()
{
return AssociationFactory::getInstance()->getMany2OneAssociation($this,'Implementation','Capabilities')->getTarget();
}
/**
* @param IOpenStackImplementation $implementation
* @return void
*/
public function setImplementation(IOpenStackImplementation $implementation)
{
AssociationFactory::getInstance()->getMany2OneAssociation($this,'Implementation','Capabilities')->setTarget($implementation);
}
/**
* @return IReleaseSupportedApiVersion
*/
public function getReleaseSupportedApiVersion()
{
return AssociationFactory::getInstance()->getMany2OneAssociation($this,'ReleaseSupportedApiVersion')->getTarget();
}
/**
* @param IReleaseSupportedApiVersion $release_supported_api_version
* @return void
*/
public function setReleaseSupportedApiVersion(IReleaseSupportedApiVersion $release_supported_api_version)
{
AssociationFactory::getInstance()->getMany2OneAssociation($this,'ReleaseSupportedApiVersion')->setTarget($release_supported_api_version);
}
/**
* @return bool
*/
public function SupportsVersioning()
{
$supported_version = $this->getReleaseSupportedApiVersion();
if(!$supported_version) return false;
$component = $supported_version->getOpenStackComponent();
if(!$component) return false;
return $component->getSupportsVersioning();
}
}

View File

@ -13,8 +13,7 @@ class OpenStackImplementationDraft
); );
static $has_many = array( static $has_many = array(
'RegionalSupports' => 'RegionalSupport', 'Capabilities' => 'OpenStackImplementationApiCoverageDraft'
'Capabilities' => 'OpenStackImplementationApiCoverage'
); );
/** /**

View File

@ -52,4 +52,19 @@ final class DistributionDraftFactory extends OpenStackImplementationFactory {
$regional_support->setCompanyService($service); $regional_support->setCompanyService($service);
return $regional_support; return $regional_support;
} }
/**
* @param int $coverage_percent
* @param IReleaseSupportedApiVersion $release_supported_api_version
* @param IOpenStackImplementation $implementation
* @return IOpenStackImplementationApiCoverage
*/
public function buildCapability($coverage_percent, IReleaseSupportedApiVersion $release_supported_api_version, IOpenStackImplementation $implementation)
{
$capability = new OpenStackImplementationApiCoverageDraft;
$capability->setCoveragePercent($coverage_percent);
$capability->setReleaseSupportedApiVersion($release_supported_api_version);
$capability->setImplementation($implementation);
return $capability;
}
} }

View File

@ -195,9 +195,14 @@ abstract class CompanyServiceCrudApi
*/ */
public function publishCompanyService(){ public function publishCompanyService(){
try { try {
$company_service_id = intval($this->request->param('COMPANY_SERVICE_ID'));
$data = $this->getJsonRequest(); $data = $this->getJsonRequest();
if (!$data) return $this->serverError(); if (!$data) return $this->serverError();
$this->manager->publishCompanyService($data); //save the draft
$this->draft_manager->updateCompanyService($data);
//save the live version
$data['id'] = $data['live_service_id'];
$this->manager->updateCompanyService($data);
return $this->published(); return $this->published();
} }
catch (EntityAlreadyExistsException $ex1) { catch (EntityAlreadyExistsException $ex1) {

View File

@ -113,7 +113,7 @@ final class DistributionCrudApi extends CompanyServiceCrudApi {
'DELETE $COMPANY_SERVICE_ID!' => 'deleteCompanyService', 'DELETE $COMPANY_SERVICE_ID!' => 'deleteCompanyService',
'POST ' => 'addCompanyService', 'POST ' => 'addCompanyService',
'PUT ' => 'updateCompanyService', 'PUT ' => 'updateCompanyService',
'PUBLISH ' => 'publishCompanyService', 'PUT $COMPANY_SERVICE_ID!' => 'publishCompanyService',
); );
/** /**
@ -145,8 +145,7 @@ final class DistributionCrudApi extends CompanyServiceCrudApi {
public function addCompanyService(){ public function addCompanyService(){
try { try {
return parent::addCompanyService(); return parent::addCompanyServiceDraft();
//return parent::addCompanyServiceDraft();
} }
catch (Exception $ex) { catch (Exception $ex) {
SS_Log::log($ex,SS_Log::ERR); SS_Log::log($ex,SS_Log::ERR);
@ -174,4 +173,15 @@ final class DistributionCrudApi extends CompanyServiceCrudApi {
} }
} }
public function deleteCompanyService(){
try {
parent::deleteCompanyService();
return parent::deleteCompanyServiceDraft();
}
catch (Exception $ex) {
SS_Log::log($ex,SS_Log::ERR);
return $this->serverError();
}
}
} }

View File

@ -380,15 +380,4 @@ abstract class CompanyServiceManager {
return $services; return $services;
} }
/**
* @param int $version_id
* @return IEntity|void
* @throws EntityAlreadyExistsException
* @throws NotFoundEntityException
*/
public function publishCompanyService(array $data){
}
} }

View File

@ -15,6 +15,8 @@
* Interface ICompanyService * Interface ICompanyService
*/ */
interface ICompanyService extends IManipulableEntity { interface ICompanyService extends IManipulableEntity {
public function isDraft();
/** /**
* @param ICompany $company * @param ICompany $company
* @return void * @return void

View File

@ -192,6 +192,7 @@ class MarketPlaceAdminPage_Controller extends Page_Controller
'consultants', 'consultants',
'consultant', 'consultant',
'preview', 'preview',
'draft_preview',
'pdf', 'pdf',
); );
@ -201,6 +202,7 @@ class MarketPlaceAdminPage_Controller extends Page_Controller
*/ */
static $url_handlers = array( static $url_handlers = array(
'GET $MARKETPLACETYPE/$ID/preview' => 'preview', 'GET $MARKETPLACETYPE/$ID/preview' => 'preview',
'GET $MARKETPLACETYPE/$ID/draft_preview' => 'draft_preview',
'GET $MARKETPLACETYPE/$ID/pdf' => 'pdf', 'GET $MARKETPLACETYPE/$ID/pdf' => 'pdf',
); );
@ -993,6 +995,64 @@ class MarketPlaceAdminPage_Controller extends Page_Controller
} }
} }
public function draft_preview()
{
$marketplace_type = $this->request->param('MARKETPLACETYPE');
$instance_id = intval($this->request->param('ID'));
$query = new QueryObject();
$query->addAddCondition(QueryCriteria::equal('ID', $instance_id));
Requirements::block("marketplace/code/ui/admin/css/marketplace.admin.css");
Requirements::block(Director::protocol() . "code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css");
switch (strtolower($marketplace_type)) {
case 'distribution': {
$distribution = $this->distribution_draft_repository->getBy($query);
if (!$distribution) throw new NotFoundEntityException('', '');
$render = new DistributionSapphireRender($distribution);
$distribution ->IsPreview = true;
return $render->draw();
}
break;
case 'appliance': {
$appliance = $this->appliance_repository->getBy($query);
$appliance->IsPreview = true;
$render = new ApplianceSapphireRender($appliance);
return $render->draw();
}
break;
case 'public_cloud': {
$public_cloud = $this->public_clouds_repository->getBy($query);
$public_cloud->IsPreview = true;
if (!$public_cloud) throw new NotFoundEntityException('', '');
$render = new PublicCloudSapphireRender($public_cloud);
return $render->draw();
}
break;
case 'private_cloud': {
$private_cloud = $this->private_clouds_repository->getBy($query);
$private_cloud->IsPreview = true;
$render = new PrivateCloudSapphireRender($private_cloud);
return $render->draw();
}
break;
case 'consultant': {
$consultant = $this->consultant_repository->getBy($query);
if (!$consultant) throw new NotFoundEntityException('', '');
$consultant->IsPreview = true;
$render = new ConsultantSapphireRender($consultant);
return $render->draw();
}
break;
default:
$this->httpError(404);
break;
}
}
public function getCurrentDataCenterLocationsJson() public function getCurrentDataCenterLocationsJson()
{ {
$instance_id = intval($this->request->param('ID')); $instance_id = intval($this->request->param('ID'));

View File

@ -46,6 +46,7 @@ jQuery(document).ready(function($){
$("#live_id",form).val(distribution.live_service_id); $("#live_id",form).val(distribution.live_service_id);
} else { //its not a draft is the live version, so we remove the id and set the live_service_id } else { //its not a draft is the live version, so we remove the id and set the live_service_id
$("#live_id",form).val(distribution.id); $("#live_id",form).val(distribution.id);
$('.publish-distribution').prop('disabled',true);
} }
//reload widgets //reload widgets
@ -109,7 +110,9 @@ jQuery(document).ready(function($){
contentType: "application/json; charset=utf-8", contentType: "application/json; charset=utf-8",
dataType: "json", dataType: "json",
success: function (data,textStatus,jqXHR) { success: function (data,textStatus,jqXHR) {
window.location = listing_url; //window.location = listing_url;
$('.publish-distribution').prop('disabled',false);
$('.save-distribution').prop('disabled',false);
}, },
error: function (jqXHR, textStatus, errorThrown) { error: function (jqXHR, textStatus, errorThrown) {
$('.save-distribution').prop('disabled',false); $('.save-distribution').prop('disabled',false);
@ -149,6 +152,7 @@ jQuery(document).ready(function($){
//create distribution object and POST it //create distribution object and POST it
var distribution = {}; var distribution = {};
distribution.id = parseInt($("#id",form).val()); distribution.id = parseInt($("#id",form).val());
distribution.live_service_id = parseInt($("#live_id",form).val());
distribution.company_id = parseInt($("#company_id",form).val()); distribution.company_id = parseInt($("#company_id",form).val());
distribution.name = $("#name",form).val(); distribution.name = $("#name",form).val();
distribution.overview = $("#overview",form).val(); distribution.overview = $("#overview",form).val();
@ -161,12 +165,13 @@ jQuery(document).ready(function($){
distribution.regional_support = regional_support; distribution.regional_support = regional_support;
distribution.additional_resources = additional_resources; distribution.additional_resources = additional_resources;
var type = 'PUBLISH'; var url = 'api/v1/marketplace/distributions/'+distribution.live_service_id;
$('.publish-distribution').prop('disabled',true);
$('.save-distribution').prop('disabled',true);
$.ajax({ $.ajax({
type: type, type: 'PUT',
url: 'api/v1/marketplace/distributions', url: url,
data: JSON.stringify(distribution), data: JSON.stringify(distribution),
contentType: "application/json; charset=utf-8", contentType: "application/json; charset=utf-8",
dataType: "json", dataType: "json",
@ -174,7 +179,7 @@ jQuery(document).ready(function($){
window.location = listing_url; window.location = listing_url;
}, },
error: function (jqXHR, textStatus, errorThrown) { error: function (jqXHR, textStatus, errorThrown) {
$('.save-distribution').prop('disabled',false); $('.publish-distribution').prop('disabled',false);
ajaxError(jqXHR, textStatus, errorThrown); ajaxError(jqXHR, textStatus, errorThrown);
} }
}); });

View File

@ -3,9 +3,9 @@
<div style="clear:both"> <div style="clear:both">
<h1 style="width:50%;float:left;">Distribution - Product Details</h1> <h1 style="width:50%;float:left;">Distribution - Product Details</h1>
<a style="overflow:hidden;white-space: nowrap;font-weight:normal;float:right;margin-bottom:50px;text-align:center" class="roundedButton save-distribution" href="#" id="save-distribution">Save</a> <a style="overflow:hidden;white-space: nowrap;font-weight:normal;float:right;margin-bottom:50px;text-align:center" class="roundedButton save-distribution" href="#" id="save-distribution">Save</a>
<a style="overflow:hidden;white-space: nowrap;font-weight:normal;float:right;margin-bottom:50px;text-align:center" class="roundedButton save-distribution" href="#" id="publish-distribution">Publish</a> <a style="overflow:hidden;white-space: nowrap;font-weight:normal;float:right;margin-bottom:50px;text-align:center;margin-right:50px;" class="roundedButton publish-distribution" href="#" id="publish-distribution">Publish</a>
<% if CurrentDistribution %> <% if CurrentDistribution %>
<a style="overflow:hidden;white-space: nowrap;font-weight:normal;float:right;margin-bottom:50px;text-align:center;margin-right:50px;" class="roundedButton addDeploymentBtn" target="_blank" href="$Top.Link(distribution)/$CurrentDistribution.ID/preview">Preview</a> <a style="overflow:hidden;white-space: nowrap;font-weight:normal;float:right;margin-bottom:50px;text-align:center;margin-right:50px;" class="roundedButton addDeploymentBtn" target="_blank" href="$Top.Link(distribution)/$CurrentDistribution.ID/draft_preview">Preview</a>
<% end_if %> <% end_if %>
<% if CurrentDistribution %> <% if CurrentDistribution %>
<a style="overflow:hidden;white-space: nowrap;font-weight:normal;float:right;margin-bottom:50px;text-align:center;margin-right:50px;" class="roundedButton addDeploymentBtn" target="_blank" href="$Top.Link(distribution)/$CurrentDistribution.ID/pdf">Download PDF</a> <a style="overflow:hidden;white-space: nowrap;font-weight:normal;float:right;margin-bottom:50px;text-align:center;margin-right:50px;" class="roundedButton addDeploymentBtn" target="_blank" href="$Top.Link(distribution)/$CurrentDistribution.ID/pdf">Download PDF</a>