|
4 | 4 | "context"
|
5 | 5 | "database/sql"
|
6 | 6 | "encoding/json"
|
| 7 | + "io/fs" |
7 | 8 | "net/http"
|
8 | 9 | "time"
|
9 | 10 |
|
@@ -37,6 +38,8 @@ func (api *API) templateVersionDynamicParameters(rw http.ResponseWriter, r *http
|
37 | 38 | user := httpmw.UserParam(r)
|
38 | 39 | templateVersion := httpmw.TemplateVersionParam(r)
|
39 | 40 |
|
| 41 | + dynamicPreview := preview.Preview |
| 42 | + |
40 | 43 | // Check that the job has completed successfully
|
41 | 44 | job, err := api.Database.GetProvisionerJobByID(ctx, templateVersion.JobID)
|
42 | 45 | if httpapi.Is404Error(err) {
|
@@ -190,6 +193,45 @@ func (api *API) templateVersionDynamicParameters(rw http.ResponseWriter, r *http
|
190 | 193 | }
|
191 | 194 | }
|
192 | 195 |
|
| 196 | +func staticPreview(ctx context.Context, db database.Store, version uuid.UUID) func(ctx context.Context, input preview.Input, fs fs.FS) preview.Output { |
| 197 | + dbTemplateVersionParameters, err := db.GetTemplateVersionParameters(ctx, version) |
| 198 | + if err != nil { |
| 199 | + return nil |
| 200 | + } |
| 201 | + |
| 202 | + params := make([]previewtypes.Parameter, 0, len(dbTemplateVersionParameters)) |
| 203 | + for _, it := range dbTemplateVersionParameters { |
| 204 | + params = append(params, previewtypes.Parameter{ |
| 205 | + ParameterData: previewtypes.ParameterData{ |
| 206 | + Name: it.Name, |
| 207 | + DisplayName: it.DisplayName, |
| 208 | + Description: it.Description, |
| 209 | + Type: previewtypes.ParameterType(it.Type), |
| 210 | + FormType: "", // ooooof |
| 211 | + Styling: previewtypes.ParameterStyling{}, |
| 212 | + Mutable: it.Mutable, |
| 213 | + DefaultValue: previewtypes.StringLiteral(it.DefaultValue), |
| 214 | + Icon: it.Icon, |
| 215 | + Options: nil, |
| 216 | + Validations: nil, |
| 217 | + Required: false, |
| 218 | + Order: 0, |
| 219 | + Ephemeral: false, |
| 220 | + Source: nil, |
| 221 | + }, |
| 222 | + Value: previewtypes.NullString(), |
| 223 | + Diagnostics: nil, |
| 224 | + }) |
| 225 | + } |
| 226 | + |
| 227 | + return func(_ context.Context, in preview.Input, _ fs.FS) preview.Output { |
| 228 | + |
| 229 | + return preview.Output{ |
| 230 | + Parameters: nil, |
| 231 | + } |
| 232 | + } |
| 233 | +} |
| 234 | + |
193 | 235 | func (api *API) getWorkspaceOwnerData(
|
194 | 236 | ctx context.Context,
|
195 | 237 | user database.User,
|
|
0 commit comments