public function actionTask($id)
 {
     $model = DiscoveryTask::findOne($id);
     $searchChange = new Change();
     $changeProvider = $searchChange->searchPending(Yii::$app->request->get(), $id);
     return $this->render('task', ['changeProvider' => $changeProvider, 'model' => $model, 'searchChange' => $searchChange]);
 }
 static function makeHtml($notification = null)
 {
     if ($notification == null) {
         return "";
     }
     $eventId = json_decode($notification->info);
     $changesSize = Change::find()->where(['sync_event_id' => $eventId])->count();
     $pendingChangesSize = Change::find()->where(['sync_event_id' => $eventId])->andWhere(['in', 'status', [Change::STATUS_PENDING, Change::STATUS_FAILED]])->count();
     $appliedChangesSize = Change::find()->where(['sync_event_id' => $eventId, 'status' => Change::STATUS_APPLIED])->count();
     $changes = Change::find()->where(['sync_event_id' => $eventId])->asArray()->groupBy(['domain'])->select(['domain'])->all();
     $title = Yii::t("notify", 'Topology change');
     if (count($changes) > 1) {
         $msg = Yii::t("notify", 'The topologies of') . " <b>" . count($changes) . "</b> " . Yii::t("notify", 'domains has been updated.') . " <b>" . $appliedChangesSize . "</b> " . Yii::t("notify", 'changes were applied.') . ' ' . ($pendingChangesSize > 0 ? " <b>" . $pendingChangesSize . "</b> " . Yii::t("notify", 'are pending.') : '');
     } else {
         if (count($changes) == 1) {
             $msg = Yii::t("notify", 'The') . " <b>" . $changes[0]['domain'] . "</b> " . Yii::t("notify", 'topology has been updated.') . " <b>" . $appliedChangesSize . "</b> " . Yii::t("notify", 'changes were applied.') . ' ' . ($pendingChangesSize > 0 ? " <b>" . $pendingChangesSize . "</b> " . Yii::t("notify", 'are pending.') : '');
         } else {
             return "";
         }
     }
     $date = Yii::$app->formatter->asDatetime($notification->date);
     $link = '/topology/change/applied?eventId=' . $eventId;
     $text = '<span><h1>' . $title . '</h1><h2>' . $msg . '</h2><h3>' . $date . '</h3></span>';
     $html = Notification::makeHtml('topology.png', $text);
     if ($notification->viewed == true) {
         return '<li>' . Html::a($html, array($link)) . '</li>';
     }
     return '<li class="new">' . Html::a($html, array($link)) . '</li>';
 }
Exemple #3
0
 private function applyChangesByType($type)
 {
     $changes = Change::find()->where(['sync_event_id' => $this->id, 'item_type' => $type])->andWhere(['in', 'status', [Change::STATUS_FAILED, Change::STATUS_PENDING]])->all();
     foreach ($changes as $change) {
         $change->apply();
     }
 }
Exemple #4
0
        <h3 class="box-title"><?php 
echo Yii::t("topology", "Discovered changes");
?>
</h3>
        <div class="box-tools">
            <button class="btn btn-sm btn-default" id="apply-all">Apply all changes</button>
        </div>
    </div>
    <div class="box-body">
        <?php 
Pjax::begin(['id' => 'change-pjax']);
echo Grid::widget(['id' => 'change-grid', 'filterModel' => $searchChange, 'dataProvider' => $changeProvider, 'columns' => array(['class' => 'yii\\grid\\ActionColumn', 'template' => '{apply}', 'buttons' => ['apply' => function ($url, $model) {
    return $model->status == Change::STATUS_APPLIED ? "" : Html::a('<span class="fa fa-check apply-btn"></span>', '#');
}], 'headerOptions' => ['style' => 'width: 2%;']], ['attribute' => 'domain', 'filter' => Html::activeDropDownList($searchChange, 'domain', ArrayHelper::map(Change::find()->where(['status' => Change::STATUS_PENDING])->asArray()->select("domain")->distinct(true)->orderBy("domain ASC")->all(), 'domain', 'domain'), ['class' => 'form-control', 'prompt' => 'any']), 'headerOptions' => ['style' => 'width: 16%;']], ['header' => Yii::t('topology', 'Type'), 'value' => function ($model) {
    return $model->getType();
}, 'filter' => Html::activeDropDownList($searchChange, 'type', ArrayHelper::map(Change::getTypes(), 'id', 'name'), ['class' => 'form-control', 'prompt' => 'any']), 'headerOptions' => ['style' => 'width: 7%;']], ['attribute' => 'item_type', 'filter' => Html::activeDropDownList($searchChange, 'item_type', ArrayHelper::map(Change::getItemTypes(), 'id', 'name'), ['class' => 'form-control', 'prompt' => 'any']), 'value' => function ($model) {
    return $model->getItemType();
}, 'headerOptions' => ['style' => 'width: 12%;']], ['attribute' => 'data', 'filter' => false, 'format' => 'raw', 'value' => function ($model) {
    return $model->getDetails();
}, 'headerOptions' => ['style' => 'width: 30%;']], ['header' => 'Status', 'filter' => false, 'format' => 'raw', 'value' => function ($model) {
    switch ($model->status) {
        case Change::STATUS_FAILED:
            return '<a href="#" title="' . $model->error . '"><span class="label label-danger">Failed</span></a>';
        case Change::STATUS_APPLIED:
            return '<span class="label label-success">Applied</span>';
        case Change::STATUS_PENDING:
            return '<span class="label label-primary">Pending</span>';
        default:
            return "";
    }
}, 'headerOptions' => ['style' => 'width: 5%;']])]);
 public function actionApply($id)
 {
     $change = Change::findOne($id);
     return $change->apply();
 }